Problem with fflush and scanf in C/C++

Правка en2, от dush1729, 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.

Теги scanf, strings, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский dush1729 2015-11-30 20:28:01 131
en1 Английский dush1729 2015-11-30 20:23:15 1018 Initial revision (published)