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
1 Like
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β;}