ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1601. AntiCAPS

Show all messages Hide all messages

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
char unCAPS(int state, char symbel)
{
    char out_symb;
    if (((int)symbel >= 65 && (int)symbel <= 90) && state ==0)
    {
        out_symb = (char)(symbel + 32);
        return out_symb;
    }

    if (((int)symbel >= 97 && (int)symbel <=122 ) && state == 1)
    {
        out_symb = (char)(symbel - 32);
        return out_symb;
    }

    return symbel;
}

int main()
{
    char str[10000] = { NULL }, str2[10000] = { NULL };
    int state = 1;
    cin.get(str, 10000);
    for (size_t i = 0; i < strlen(str); i++)
    {
        str2[i] = unCAPS(state, str[i]);
        if ((int)str[i] != 32)
        {
            state = 0;
        }
        if ((int)str[i] == 46 || (int)str[i] == 33 || (int)str[i] == 63)
        {
            state = 1;
        }

    }
    for (size_t i = 0; i < strlen(str2); i++)
    {
        cout << str2[i];
    }

    return 0;
}
Ты тестировал локально? Если нет, то попробуй. В http://acm.timus.ru/help.aspx?topic=cpp в самом конце указано, как пользоваться #ifndef ONLINE_JUDGE (на сервере этот код не выполнится, а у себя на компьютере тестировать удобно). И смотри, нет ли на выводе, например, лишних пробелов в конце или вроде того.
You don't need conio.h
You should use csting or string.h for strcpy.
Did you really try to compile and run it?

You shouldn't use ascii codes. "str[i] == '.'" is better then "(int)str[i] == 46".
Why do you think that first non-space symbol in sentence is word? Why not "-"?
You should read task carefuly. 2 lines in example is 1 test. You only process first line.