快读快写模板 Pro Max

模板

namespace QuickIO {
    template<typename T> inline void read(T &x) {
        x = 0; signed op = 1; char ch = getchar();
        for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1;
        for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
        x *= op;
    }
    template<typename T, typename ...Args> inline void read(T &x, Args &...rest) {
        read(x), read(rest...);
    }
    template<typename T> void write(T x) {
        if (x < 0) putchar('-'), x = -x;
        if (x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
    template<> void write<char>(char x) {
        putchar(x);
    }
    template<typename T, typename ...Args> void write(T x, Args ...rest) {
        write(x), write(rest...);
    }
}

使用例

#include <bits/stdc++.h>
using namespace std;

namespace QuickIO {
    template<typename T> inline void read(T &x) {
        x = 0; signed op = 1; char ch = getchar();
        for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1;
        for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
        x *= op;
    }
    template<typename T, typename ...Args> inline void read(T &x, Args &...rest) {
        read(x), read(rest...);
    }
    template<typename T> void write(T x) {
        if (x < 0) putchar('-'), x = -x;
        if (x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
    template<> void write<char>(char x) {
        putchar(x);
    }
    template<typename T, typename ...Args> void write(T x, Args ...rest) {
        write(x), write(rest...);
    }
}

int main() {
    // 使用例
    int a;
    long long b;
    short c;
    QuickIO::read(a, b, c); // 读入列表长度可变,类型不限(前提是整数)
    QuickIO::write(a, '+', b, '+', c, '=', a + b + c, '\n'); // 同样长度可变,并且可以一并输出单个字符
    return 0;
}
posted @ 2024-11-23 10:35  jxyanglinus  阅读(44)  评论(0)    收藏  举报