Hey! I’ve read at many places while searching for fast i/o methods that getchar unlocked() is the fastest.But,as i’m using windows it doesn’t work on my machine,instead getchar() worked.But I’m not able to understand how it is used,i mean to say what’s actually happening in the following code snippet which i’ve seen is used for fast i/o.
inline void scanint(long long int &x)
{
register long long int c = getchar();
x = 0;
long long int neg = 0;
for(;((c<48 || c>57) && c != '-');c = getchar());
if(c=='-') {neg=1;c=getchar();}
for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
if(neg) x=-x;
}
int main()
{long long int n;
scanint(n);
return 0;
}
Can anyone please explain what’s happening in the above code? Also
How to start writing the code for fast i/o using getchar()?
Thanks!! For your Help.