ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1446. Волшебная шляпа

WA1 Really!
Послано VNXtreMe 3 янв 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!
Послано VNXtreMe 4 янв 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 :
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:41
Re: WA1 Really!
Послано Mostafa Khalid Raihan 9 дек 2013 23:52
Thanks... great help indeed ... :)