模板 - 算法基础 - 输入输出

template<typename T>
void Scanf(T &x) {
    x = 0;
    char c = getchar();
    while(!isdigit(c))
        c = getchar();
    while(isdigit(c)) {
        x = x * 10 + (c - '0');
        c = getchar();
    }
}
 
template<typename T1, typename T2>
void Scanf(T1 &x1, T2 &x2) {
    Scanf(x1);
    Scanf(x2);
}
 
template<typename T1, typename T2, typename T3>
void Scanf(T1 &x1, T2 &x2, T3 &x3) {
    Scanf(x1);
    Scanf(x2);
    Scanf(x3);
}
 
template<typename T1, typename T2, typename T3, typename T4>
void Scanf(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
    Scanf(x1);
    Scanf(x2);
    Scanf(x3);
    Scanf(x4);
}
 
template<typename T>
void Scanf(T* a, int n) {
    for(int i = 1; i <= n; ++i)
        Scanf(a[i]);
}
 
template<typename T>
void _Printf(T x) {
    if(x >= 10)
        _Printf(x / 10);
    putchar('0' + x % 10);
}
 
template<typename T>
void Printf(T x, const char& c = '\n') {
    _Printf(x);
    putchar(c);
}
 
template<typename T1, typename T2>
void Printf(T1 &x1, T2 &x2) {
    Printf(x1, ' ');
    Printf(x2, '\n');
}
 
template<typename T1, typename T2, typename T3>
void Printf(T1 &x1, T2 &x2, T3 &x3) {
    Printf(x1, ' ');
    Printf(x2, ' ');
    Printf(x3, '\n');
}
 
template<typename T1, typename T2, typename T3, typename T4>
void Printf(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
    Printf(x1, ' ');
    Printf(x2, ' ');
    Printf(x3, ' ');
    Printf(x4, '\n');
}
 
template<typename T>
void Printf(T* a, int n) {
    for(int i = 1; i < n; ++i)
        Printf(a[i], ' ');
    Printf(a[n], '\n');
}
 
void YES() {
    puts("YES");
}
 
void NO() {
    puts("NO");
}
posted @ 2019-11-29 12:09  KisekiPurin2019  阅读(150)  评论(0编辑  收藏  举报