C++两种快速读入

无返回值:

inline void read(int& x) {
    x = 0;
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
}

用法:read(a).

 

有返回值:

inline int read() {
    char ch = getchar();
    int x = 0, f = 1;
    while (ch > '9' || ch < '0') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

用法:a=read().

posted @ 2021-01-06 11:07  goverclock  阅读(290)  评论(0编辑  收藏  举报