基础题,使用 set 数据结构即可。
#include <iostream>
#include <set>
using namespace std;
set<int> s;
int main()
{
int n, m;
while (cin >> n >> m)
{
s.clear();
int num;
for (int i = 0; i < n + m; i++)
{
cin >> num;
s.insert(num);
}
int total = 0;
set<int>::iterator it;
for (it = s.begin(); it != s.end(); it++)
{
cout << *it << " ";
++total;
if (total + 1 == s.size())
{
cout << *(++it) << endl;
break;
}
}
}
return 0;
}
继续加油。