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

Обсуждение задачи 1427. SMS

What was the trick in the 7th test? I cannot deal with it!!!
Послано Игорь Степанов 11 фев 2006 19:54
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Igor E. Tuphanov 12 фев 2006 05:38
Trick was with I\O. I held half of contest myselt trying to pass it. If you use C\C++, you may have the same bug. Reading
scanf("%d%d\n",&n,&m); gets(a);
got WA#7, but this code
scanf("%d%d",&n,&m); gets(a); gets(a);
got AC. Why? I don't know! But it would be better to learn more about this bug. What do you think about it?
your first code is indeed wrong.
Послано Safe Bird 12 фев 2006 14:50
Re: your first code is indeed wrong.
Послано Naked Chick 12 фев 2006 15:06
Safe Bird can you explain why his first code is wrong?
I think i have to say "No Comment" here... sorry.
Послано Safe Bird 12 фев 2006 15:51
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Vladimir Yakovlev (USU) 12 фев 2006 16:25
scanf("%d%d\n",&n,&m) reads not only new line character but leading spaces in second line.
If you use C++, you must know it!
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Denis Koshman 5 авг 2008 01:03
Don't mix up 'scanf' and 'gets' or you will have unpredictable am-I-before-or-after-EOL situations. If you have to use 'gets' in the problem, use ONLY 'gets', and use 'sscanf' to extract row elements from the string fetched via 'gets', or use 'strtok' if you don't know amount of elements beforehand. For this particular problem I wrote:

gets(s);
sscanf(s, "%d %d", &n, &m);
gets(s);
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Sasha Bar [TNU] 12 авг 2008 22:07
>> scanf("%d%d\n",&n,&m) reads not only new line character  but leading spaces in second line.
>> If you use C++, you must know it!

Thank you for explain! :)

Edited by author 12.08.2008 22:09
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Tim 4 окт 2008 16:42
2Igor E. Tuphanov
Thank you! You are very helpful!
Re: What was the trick in the 7th test? I cannot deal with it!!!
Послано Ade 10 апр 2017 22:05
Thank you for your useful tip!
I didn't find any document about this behavior. Your experience is really great.