T764812的题解

· · 个人记录

大炮打蚊子如下 解法一:

#include <iostream>
const char hello[] = "Hello,World!";
template <int N>
struct Printer {
    static void print() {
        Printer<N - 1>::print();
        std::cout << hello[N];
    }
};
template <>
struct Printer<0> {
    static void print() {
        std::cout << hello[0];
    }
};
template <int Size>
void complexPrint() {
    Printer<Size - 1>::print();
    std::cout << std::endl;
}
int main() {
    complexPrint<12>();
    return 0;
}
//关于我刚学OI时在机房难受地做了3个小时

解法二:

#include <iostream>
const char hello[] = "Hello,World!";
template <int N>
struct Printer {
    static void print() {
        Printer<N - 1>::print();
        std::cout << hello[N];
    }
};
template <>
struct Printer<0> {
    static void print() {
        std::cout << hello[0];
    }
};
template <int Size>
void complexPrint() {
    Printer<Size - 1>::print();
    std::cout << std::endl;
}
int main() {
    complexPrint<12>();
    return 0;
}```cpp
#include <iostream>
#include <array>
#include <algorithm>
#include <iterator>
int main() {
    std::array<char, 12> message = {
        'H', 'e', 'l', 'l', 'o', ',',
        'W', 'o', 'r', 'l', 'd', '!'
    };
    std::copy(
        message.begin(), 
        message.end(), 
        std::ostream_iterator<char>(std::cout, "")
    );
    std::cout << std::endl;
    return 0;
}