Input/Output in c and c++ programs using BUFFER method

Since last two days i read a submit solution of Turbo Sort problem(easy section) CodeChef: Practical coding for everyone of user “Siva Reddy”

and i am not getting any idea about the solution . He used BUFFER method in his program .
Can anybody tell me the best links or tutorial , as soon as possible, from where i can learn this method .

This method really solve the problem of TIME LIMIT EXCEED which mostly occurs in my programs.
So plz help me.

I haven’t gone through the code completely. He is reading the whole input file(stdin) into a buffer and then parsing the buffer. This is much faster than formatted input functions. Alternatively you can use getchar_unlocked() (which i believe to be simpler to code) which is also significantly faster than reading input through formatted io. You may check the following program to get an idea.

fast io using getchar_unlocked()

1 Like