int read() { char c=getchar();int num=0; for(;!isdigit(c);c=getchar()); for(;isdigit(c);c=getchar()) num=num*10+c-'0'; return num; }
考虑负数:
inline int read() { char ch=getchar(); int x=0,f=1; while((ch>'9'||ch<'0')&&ch!='-') ch=getchar(); if(ch=='-') { f=-1; ch=getchar(); } while('0'<=ch&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; }
关于cin,scanf,getchar 速度的比较可参考: