用标准库stl的set自动排序加去重
#include <algorithm>
#include <set>

using namespace std;

int main() {
    int n1,n2;
    while(cin>>n1){
        set<int> iset;
      for(int i = 0;i<n1;i++){
          int temp;
          cin>>temp;
          iset.insert(temp);
          
      }
        cin>>n2;
        for(int j = 0;j<n2;j++){
            int temp;
            cin>>temp;
            iset.insert(temp);
            
        }
        for(auto it = iset.begin();it!=iset.end();it++){
            cout<<(*it);
            
        }
        
    }
}