【模板】快读快写

发布时间 2023-05-01 12:55:37作者: GOD_HJ

快读

inline int read() {//整数
    int x = 0;
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

inline double fread() {//浮点数
    double x = 0, y = 1.0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') y = -1.0;
        c = getchar();
    }
    while (isdigit(c) || c == '.') {
        if (isdigit(c)) x = x * 10 + c - '0';
        else {
            double t = 0.1;
            c = getchar();
            while (isdigit(c)) {
                x += (c - '0') * t;
                t *= 0.1;
                c = getchar();
            }
            break;
        }
        c = getchar();
    }
    return x * y;
}

快写

inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}