使用STL set,set会自动去重和排序。

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

int main(){
    int n;
    while(cin >> n){
        set<int> set;
        for(int i = 0; i < n; i++){
            int temp;
            cin >> temp;
            set.insert(temp);
        }
        int m;
        cin >> m;
        for(int i = 0; i < m; i++){
            int temp;
            cin >> temp;
            set.insert(temp);
        }
        for(auto i : set){
            cout << i;
        }
    }
    cout << endl;
    return 0;
}