Alternative to using printf repeatedly

What is the best way to display output quickly? Is it recommended to write all output to one string and then print the string at once? Are there any libraries for quick input/output?

There is no any special library in C/C++ for FASTIO.

The Fastest Method to print output in C/C++ is fwrite or fwrite_unlocked in stdio.h library.

Also there isn’t any special/Direct function to print output at once .

Indirectly,it can be achieved using append function ( appending all output strings to one single string and printing the final string)in cplusplus
and even strcat function in string.h lib,but performance wise ,“Appending or concat + printing”,is slower ,even far slower than printf.

So the fastest way in c/c++ is :directly read the stream in the raw form, and extract the information required.Also put the output in raw form in a huge buffer and display it finally using fwrite.

And please try to go through the solution in this link for fast IO .

4 Likes

I don’t know about you guys, but I prefer using getchar_unlocked() for fast input.

2 Likes

There is no direct way

i convert the whole answer into a single string and then output through puts(). Sometimes it helps me to submit the quickest solution on spoj

1 Like

Never, in any serious algorithmic contest, should I/O faster than scanf/printf be required. Otherwise, it just shows that the authors are unable to create difficult enough problems and need to resort to requiring complex knowledge of the programming language (not to mention it might be impossible to solve such problems in some languages).

11 Likes

i convert the whole answer into a single string and then output through puts(). Sometimes it helps me to submit the quickest solution on spoj

1 Like
//