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 1427. SMS

What was the trick in the 7th test? I cannot deal with it!!!
Posted by Игорь Степанов 11 Feb 2006 19:54
Re: What was the trick in the 7th test? I cannot deal with it!!!
Posted by Igor E. Tuphanov 12 Feb 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.
Posted by Safe Bird 12 Feb 2006 14:50
Re: your first code is indeed wrong.
Posted by Naked Chick 12 Feb 2006 15:06
Safe Bird can you explain why his first code is wrong?
I think i have to say "No Comment" here... sorry.
Posted by Safe Bird 12 Feb 2006 15:51
Re: What was the trick in the 7th test? I cannot deal with it!!!
Posted by Vladimir Yakovlev (USU) 12 Feb 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!!!
Posted by Denis Koshman 5 Aug 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!!!
Posted by Sasha Bar [TNU] 12 Aug 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!!!
Posted by Tim 4 Oct 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!!!
Posted by Ade 10 Apr 2017 22:05
Thank you for your useful tip!
I didn't find any document about this behavior. Your experience is really great.