Problem with fflush and scanf in C/C++

Revision en2, by div24ever, 2015-11-30 20:28:01

I have encountered weird behaviour with character arrays/strings on various websites. For example take these two submissions — First submission Second submission. I have just removed fflush(stdin) from my first submission and got AC. I faced similar issue with this problem. This submission has scanf without fflush(stdin) and it got runtime error but according to previous logic it should have got AC. Now this submission with fflush(stdin) and scanf also got runtime error. But this submission with cin got AC.

So my question is what should i do to prevent such nasty errors during contest? cin is slower than scanf so i prefer scanf.

EDIT — For first problem, i saw that i have used different versions of C++. In C++ 11 it gave WA but in C++ it gave AC.

Tags scanf, strings, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English div24ever 2015-11-30 20:28:01 131
en1 English div24ever 2015-11-30 20:23:15 1018 Initial revision (published)