What was the trick in the 7th test? I cannot deal with it!!!
Re: What was the trick in the 7th test? I cannot deal with it!!!
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.
Re: your first code is indeed wrong.
Safe Bird can you explain why his first code is wrong?
I think i have to say "No Comment" here... sorry.
Re: What was the trick in the 7th test? I cannot deal with it!!!
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!!!
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!!!
>> 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.