超级输入模板

来源:互联网 发布:卖帽子的淘宝销量 编辑:程序博客网 时间:2024/05/17 22:51

超级输入模板

模板解读:只可以每次读取一个int型数字,在大数据读取的时候优势明显。
例如:
int a ; read(a);

namespace fastIO {    #define BUF_SIZE 1000000    //fread -> read    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');    }    #undef BUF_SIZE};using namespace fastIO;
原创粉丝点击