【转】数据输入加速
1 //适用于正整数 2 template <class T> 3 inline void scan_d(T &ret) { 4 char c; ret=0; 5 while((c=getchar())<'0'||c>'9'); 6 while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar(); 7 }
1 //适用于正负整数 2 template <class T> 3 inline bool scan_d(T &ret) { 4 char c; int sgn; 5 if(c=getchar(),c==EOF) return 0; //EOF 6 while(c!='-'&&(c<'0'||c>'9')) c=getchar(); 7 sgn=(c=='-')?-1:1; 8 ret=(c=='-')?0:(c-'0'); 9 while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); 10 ret*=sgn; 11 return 1; 12 }
1 //适用于正负数,(int,long long,float,double) 2 template <class T> 3 bool scan_d(T &ret){ 4 char c; int sgn; T bit=0.1; 5 if(c=getchar(),c==EOF) return 0; 6 while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar(); 7 sgn=(c=='-')?-1:1; 8 ret=(c=='-')?0:(c-'0'); 9 while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); 10 if(c==' '||c=='\n'){ ret*=sgn; return 1; } 11 while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10; 12 ret*=sgn; 13 return 1; 14 }
inline void out(int x) { if(x>9) out(x/10); putchar(x%10+'0'); }
转自:http://blog.csdn.net/shahdza/article/details/6317011