快读

· · 个人记录

struct IO{
    IO(){};char c;
    inline char gc(){
        static char buf[maxn],*p1=buf,*p2=buf;
        return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    inline IO&operator>>(T &_){
        _=0;bool f=1;c=gc();while(c<'0'||c>'9'){if(c=='-') f=0; c=gc();}
        while(c>='0'&&c<='9'){_=_*10+c-48;c=gc();}if(!f) _=-_;return *this;
    }
    char buf[maxn];int p = 0;~IO(){fwrite(buf,1,p,stdout);}
    inline void pc(const char &c){
        buf[p++] = c;
        if(p==maxn) fwrite(buf,1,maxn,stdout),p=0;
    }
    template<typename T>
    inline IO&operator<<(T x){
        if(!x){pc(48);pc('\n');return *this;}static int wt[41],len;len=0;if(x<0){pc('-');x=-x;}
        for(;x;x/=10){wt[++len]=x%10;}
        while(len){pc(wt[len--]+48);}pc('\n');return *this;
    }
    inline IO&operator>>(char s[]){
        c=gc();int len=-1;while(c==' '||c=='\n'||c=='\r') c=gc();
        while(c!=' '&&c!='\n'&&c!='\r'&&c!='\0'&&c!=EOF){s[++len]=c;c=gc();}
        s[++len]='\0';return *this;
    }
    inline IO&operator<<(char s[]){
        for(int i=0;s[i]!='\0';i++) pc(s[i]);
        pc('\n');return *this;
    }
    inline IO&operator<<(char c){return pc(c),*this;}
}io;

用法举例:io>>n;(输入n)

io<<x(输出x)

以Ctrl+D结束读入(linux环境)