which one is faster, scanf or getchar

Please explain this , I am using scanf in my C++ code for chef and functions and I am getting TLE. Help


Though I think this question lies along the fringes of the contest rules, I will answer.

getchar is usually much faster than scanf. But I do not think this will help you much in the said question unless your logic is rock solid.

you rarely get TLE for using slow I/O on codechef. If at all you have to use fast I/O it is generally written in the question. You need to use a better algorithm.
Now answering your question.


in decreasing order of fastness.
Also note that getchar_unlocked() is not thread safe.


getchar is much faster. But it won’t matter in question FUNC, because that is very tough question i think related to time optimization.

getchar() is faster than scanf(). I think TLE must be due to your in-efficient algo(no offense :slight_smile: ).i also did not get the idea…:smiley: Keep trying.You will succeed.:smiley:

Happy Coding