关于输入输出及编译优化 模板代码

#define pro __attribute__((optimize("-Os")))
char cha[90000000],*ptr=cha;
char chout[10000000],*pout=chout;
pro inline void read(int &x) {
     bool flag = 0;register char c;
     while((c=getchar())>'9'||c<'0')
       if(c == '-') flag = 1;
     x = c-'0';
     while((c=getchar())<='9'&&c>='0')
      x = ((x<<1)+(x<<3))+c-'0';
     if(flag) x = -x;  
}
pro inline void out(int x) {
    if(!x)*pout++='0';
    int p=0;char buf[10];
    while(x) buf[++p]=x%10+'0',x/=10;
    while(p) *pout++=buf[p--];
    *pout++='
';
}
int main(){
    fread(ptr,1,90000000,stdin);
    x=read();
    out(x);
    fwrite(chout,1,pout-chout,stdout);
}
原文地址:https://www.cnblogs.com/shenben/p/6369521.html