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.