快读模板

快速读入字符

inline char readc(){ 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

快速读入数字

inline int readint(){
    register char c=readc();
    register int res=0;
    register bool f=1;
    while(!isgraph(c))c=readc();
    if(c=='-')f=0,c=readc();
    while(isdigit(c))res=(res+res<<2)<<1+c^0x30,c=readc();
    if(f)return res;
    return ~res+1;
}

inline int readint(){
    char c; int r;
    while(c = readc()){if(c >= '0' && c <= '9'){r = c^0x30;break;}}
    while(isdigit(c = readc()))r = (r<<3)+(r<<1)+(c^0x30);
    return r;
}

 快速读入字符串

inline int read_string(char *str){
    int len = 1;char c;
    while(!isalpha(c = readc()));str[0] = c;
    while(isalpha(c = readc()))str[len++] = c;
    str[len] = 0;
    return len;
}
原文地址:https://www.cnblogs.com/bennettz/p/7515901.html