Sunday, 5 January 2014

Why do competitive programmers prefer scanf() and printf() over cin and cout in C++?

AFAIK it is not a good habit to mix c and c++ codes. printf() and scanf() are C I/O functions. In C++, I should use cin and cout, yet I see many ppl using scanf() and printf() in competitive programming scenarios. The aim is to achieve improvement in time.

I feel that no problem setter should set a problem where the use of fast I/O is the critical step as that would mean inculcating bad practice. I recently came across one such problem in code chef:
http://www.codechef.com/JAN14/problems/FGFS/

Here,  using cin for input gave me a TLE (time limit exceed) error, while the answer got accepted with scanf().  May be my algorithm was not optimal, but in my knowledge my algorithm is the most used algorithm for the above problem.
May be I should post this question on Quora.(http://www.quora.com/C++-programming-language/Why-do-competitive-programmers-prefer-scanf-and-printf-over-cin-and-cout-in-C++)




No comments:

Post a Comment