fastest way to take input from stdin

in many online coding competition i found that questions of kind : we have to make a program such that it take input from stdin in very short time .
so is there any way other than scanf and cin so that time limit excceded problem can be avoided ?

focus on algorithm ,fast I/O is not much needed

2 Likes

correct algorithm and optimized code can fetch you AC,however there are faster i/o methods…

use getchar_unlocked();/putchar_unlocked.
takes integer input

inline void get(int &x){register int c=gc;x=0;int neg=0;for(;((c<48||c>57)&&c!=’-’);c=gc);if(c==’-’){neg = 1;c=gc;}for(;c>47&&c<58;c=gc){x=(x<<1)+(x<<3)+c-48;}if(neg)x=-x;}

gives integer output

inline void put(int n){int i=0;char ch[20];if(n==0)pc(‘0’);while(n>0)ch[i]=(n%10)+‘0’,n=n/10,i++;while(i>0)pc(ch[i-1]),i–;}