[板子]快速讀入

來源:互聯網
上載者:User

標籤:pre   mes   ||   char   sync   false   name   sign   getchar   

iostream
    ios::sync_with_stdio(false);    cin.tie(0);}
getchar() 版
// for Integerstemplate <class T> inline void read(T &x) {    x = 0; int ch = getchar(), f = 0;    while (ch < '0' || ch > '9') {        if (ch == '-') f = 1;        ch = getchar();    }    while (ch >='0' && ch <='9') {        x = (x << 1) + (x << 3) + (ch ^ 48);        ch = getchar();    }    if (f) x = -x;}
fread() 版
namespace fastIO{    #define BUF_SIZE 100000    #define OUT_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';}    template<class T> inline bool read(T &x){        bool sign = 0; char ch = nc(); x = 0;        for(; blank(ch); ch = nc());        if(IOerror) return false;        if(ch == '-') sign = 1, ch = nc();        for(; ch >= '0' && ch <= '9'; ch = nc()) x = (x << 1) + (x << 3) + (ch ^ 48);        if(sign) x = -x;        return true;    }    inline bool read(double &x){        bool sign = 0; char ch = nc(); x = 0;        for(; blank(ch); ch = nc());        if(IOerror) return false;        if(ch == '-') sign = 1, ch = nc();        for(; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10.0 + (ch ^ 48);        if(ch == '.') {            double tmp = 1; ch = nc();            for(; ch >= '0' && ch <= '9'; ch = nc()) tmp /= 10.0, x += tmp * (ch ^ 48);        }        if(sign) x = -x;        return true;    }    inline bool read(char *s){        char ch = nc();        for(; blank(ch); ch = nc());        if(IOerror) return false;        for(; !blank(ch) && !IOerror; ch = nc()) *s++ = ch;        *s = 0;        return true;    }    template<class T,class... U>bool read(T& h,U&... t){return read(h)&&read(t...);}    #undef OUT_SIZE    #undef BUF_SIZE}using namespace fastIO;

注意: template<class T,class... U>bool read(T& h,U&... t){return read(h)&&read(t...);}c++11裡規定的,考試時應該禁止使用

[板子]快速讀入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.