fread 的读入

碰到HDU 2993这道傻逼题,调了一下午我还一直以为是自己写的有问题,结果竟然卡快读,迫不得已使用了fread...
比如这种数据
N M
x1 x2 ... xn
应该这样读= =

namespace fastIO {
    #define BUF_SIZE 100000
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if(p1==pend){
            p1=buf;
            pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if(pend==p1) {
                IOerror=1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch==' '||ch=='\n'||ch =='\r'||ch=='\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x=ch-'0';(ch=nc())>='0' && ch<='9';x=x*10+ch-'0');
    }
    inline void read(long long int &x) {
        char ch;
        while(blank(ch=nc()));
        if(IOerror) return;
        for(x=ch-'0';(ch=nc())>='0' && ch<='9';x=x*10+ch-'0');
    }
    #undef BUF_SIZE
};

int main(){
    int N,M;
    while(fastIO::read(N),!fastIO::IOerror){
        fastIO::read(M);
        for(RG i=1;i<=N;++i){
            int x;
            fastIO::read(x);
        }
    }
    return;
}

猜你喜欢

转载自www.cnblogs.com/AEMShana/p/13388309.html