|
|
вернуться в форумWA1 Really! This is one of the easiest problem in timus and I can't believe i'm getting WA1 for this problem. Im solving this problem using C++ and I'm using getline method from sstream to get the input. I'm storing the names in vectors and printing them with empty lines between the houses. I know Test 1 is usually the given data, but im getting WA1 even though I'm getting the same answer in my computer as given in the problem description. Does anyone know how to overcome this WA1 problem? Edited by author 03.01.2012 15:53 Re: WA1 Really! Ok so I found the problem, I know timus is piping the input and output via text files and the problem in that was that repeated getlines will fail. So I used the piping method as mentioned in timus and the problem was visible as it printed empty output to the output file. If you want to know how to pipe inputs and outputs follow the below link(look under Other notes section)- http://acm.timus.ru/help.aspx?topic=cppFor example : cin>>number; while(true){ getline(cin,input1); getline(cin,input2); if(somecondition) break; } However while(getline(cin,input)) {do} will work. But since we need 2 inputs the above code will fail as getline will return empty strings due to the reasons mentioned here- http://www.cplusplus.com/forum/articles/6046/ I overcame the problem using cin.ignore() just before entering the loop as to flush the input stream correctly and the corrected code of above may look like the code below- cin>>number; cin.ignore();//flushes input stream while(true){ getline(cin,input1); getline(cin,input2); if(somecondition) break; } If this didn't work then I suggest you to program in other languages. Edited by author 04.01.2012 10:41Re: WA1 Really! Thanks... great help indeed ... :) |
|
|