无脑调用标准库
#include <iostream> #include <set> int main(int argc, char const *argv[]) { std::set<int> ms; int n1 = 0, n2 = 0; int num1 = 0,num2 = 0; std::cin >> n1; for (int i = 0; i < n1; i++) { std::cin >> num1; ms.insert(num1); } std::cin >> n2; for (int i = 0; i < n2; i++) { std::cin >> num2; ms.insert(num2); } for (auto it : ms) { std::cout << it; } std::cout << std::endl; return 0; }