码迷,mamicode.com
首页 > 其他好文 > 详细

【模版】快速读入/输出

时间:2018-12-24 20:24:08      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:lin   code   tchar   git   sdi   har   print   inline   bool   

快速读入模版

template < class T > inline void read(T &x) {
    x = 0;
    char c = getchar();    
    bool f = 0;
    while (!isdigit(c)) {
        f ^= c == ‘-‘;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
    if (f)
        x = ~x + 1;
}

快速输出模版

template < class T > inline void print(T x) {
    if (x < 0) {
        putchar(‘-‘);
        x = ~x + 1;
    }
    if (x > 9)
        print(x / 10);
    putchar(48 + x % 10);
}

【模版】快速读入/输出

标签:lin   code   tchar   git   sdi   har   print   inline   bool   

原文地址:https://www.cnblogs.com/heartlesser/p/10170688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!