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

Discussion of Problem 1446. Sorting Hat

WA1 Really!
Posted by VNXtreMe 3 Jan 2012 15:51
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!
Posted by VNXtreMe 4 Jan 2012 10:40
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=cpp
For example :
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.ignore();//flushes input stream
if(somecondition) break;

 If this didn't work then I suggest you to program in other languages.

Edited by author 04.01.2012 10:41
Re: WA1 Really!
Posted by Mostafa Khalid Raihan 9 Dec 2013 23:52
Thanks... great help indeed ... :)