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 1226. esreveR redrO

I don't understand
Posted by sklyack 23 Mar 2010 01:14
why this sol (C++)
///////////////////
#include <iostream>
using namespace std;
int main()
{
    char text[256001];
    int i, wbeg=-1;
    for(i=0;; i++)
    {
        cin.get(text[i]);if(cin.eof())break;
        if(('A'<=text[i] && text[i]<='Z') || ('a'<=text[i] && text[i]<='z'))
        {
            if(wbeg==-1)
                wbeg=i;
        }
        else
            if(wbeg!=-1)
            {
                for(int j=wbeg; j<(i-wbeg)/2+wbeg; j++)
                {
                    char tmp=text[j];
                    text[j]=text[i-1-j+wbeg];
                    text[i-1-j+wbeg]=tmp;
                }
                wbeg=-1;
            }
    }
    for(int j=0; j<i; j++)
        cout<<text[j];
    return 0;
}
////////////////////////////

returns WA#10, and this sol
////////////////////////////
#include <iostream>
using namespace std;
int main()
{
    char text[256001];
    int i, wbeg=-1;
    for(i=0; !cin.eof(); i++)
    {
        cin.get(text[i]);
        if(('A'<=text[i] && text[i]<='Z') || ('a'<=text[i] && text[i]<='z'))
        {
            if(wbeg==-1)
                wbeg=i;
        }
        else
            if(wbeg!=-1)
            {
                for(int j=wbeg; j<(i-wbeg)/2+wbeg; j++)
                {
                    char tmp=text[j];
                    text[j]=text[i-1-j+wbeg];
                    text[i-1-j+wbeg]=tmp;
                }
                wbeg=-1;
            }
    }
    for(int j=0; j<i-1; j++)
        cout<<text[j];
    return 0;
}
////////////////

returns AC?????
I only replaced the !cin.eof condition.
I don't understand, what the difference in the running of this programms. They returned the same answers in all of my tests!

Edited by author 23.03.2010 01:16

Edited by author 23.03.2010 01:27
hammaga omad
Posted by Botir215 13 May 2011 02:08
ushbu dasturda ahamiyatli joylari bor yani  .,?! Shu singari belgilar har bir satrning oxirida kelishi kerak.botir_studio@mail.ru
Re: I don't understand
Posted by AterLux 13 May 2011 14:06
Try test where last line do not ends with CR/LF