ACM中的fread读入

fread可以加快读入速度,尤其是读特大的二进制文件。

#include <cctype>
typedef long long LL;
char buf[100000],*p1=buf,*p2=buf;
inline char nc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline bool rea(int & x){
    char c=nc();x=0;
    if(c==EOF) return false;
    for(;!isdigit(c);c=nc());
    for(;isdigit(c);x=x*10+c-'0',c=nc());
    return true;
}
inline bool rea(LL & x){
    char c=nc();x=0;
    if(c==EOF) return false;
    for(;!isdigit(c);c=nc());
    for(;isdigit(c);x=x*10+c-'0',c=nc());
    return true;
}

ps. 向lyg要的代码。处理负数需要自己加上去。

原文地址:https://www.cnblogs.com/flipped/p/7253311.html