Can someone explain what is scanf, printf and why should we use this ? compared to cin and cout and also how do we use this, i am new to coding on online judges.language-C++
scanf/printf are faster than cin/cout because the overheads involved in using cin/cout are more as compared to scanf/printf.
iostream makes use of stdio’s buffering system. cin wastes time synchronizing itself with the underlying C-library’s stdio buffer.
So we can turn off synchronization of all the iostream standard streams with their corresponding standard C streams using libstdc++ option, std::ios::sync_with_stdio(false);
this should make cin faster.
you can make the code execute more faster by using getchar_unlocked() which is the unsafe version of getchar().
here is my code in which I used getchar_unlocked() - http://www.codechef.com/viewsolution/1949434
Thanks a lot