Does scanf cause any problems?

I submitted 2 solutions to the July Cookoff 2020 problem Even-tual Reduction(https://www.codechef.com/problems/EVENTUAL) in the practice section.
Both the solutions are identical except that the number of testcases taken through the first one is by scanf and in the second one by cin. I got WA for first and AC for second and I couldn’t figure out why. Can anyone explain what’s the error with scanf ?

https://www.codechef.com/viewsolution/35816897 (with scanf)

https://www.codechef.com/viewsolution/35817717 (with cin)

yes i debug and found that n is taking garbage value in scanf. May be because scanf leaves newline character.

1 Like

Thanks a lot for the help !

See e.g. here.

1 Like