Fast IO Optimization in C++

Lets say you have take an input of 10^5 numbers, there are many methods1. std::cin>>xyou can use std::cin which is a standard method to obtain input from STDIN how ever there are better methods2. scanf(“%d”,&x);scanf / printf are roughly thrice as fast as the cin/cout3. FAST IO
void fastscan(int &x)
bool neg=false;
register int c;
x =0;
neg = true;
for(;(c>47 && c<58);c=getchar())
x = (x<<1) + (x<<3) +c -48;
x *=-1;

fastscan(x);this is one of the fastest way to take an integer input from STDIN
this is around 10 times faster than scanf()
This is very useful in competetive programmingNOTE : You can add
in main() function
to make your cin adn cout faster

News Reporter

Leave a Reply

Your email address will not be published. Required fields are marked *