给你两个集合,要求{A} + {B}.
注:同一个集合中不会有两个相同的元素.
Input
每组输入数据分为三行,第一行有两个数字n,m(0<n,m<=10000),分别表示集合A和集合B的元素个数.后两行分别表示集合A和集合B.每个元素为不超出int范围的整数,每个元素之间有一个空格隔开.
Output
针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出,每个元素之间有一个空格隔开.
Sample
Input
1 2
1
2 3
1 2
1
1 2
Output
1 2 3
1 2
思路
一个集合中,任何两个元素都认为是不相同的,即每个元素只能出现一次。
AC代码
#include <iostream>
#include <set>
#define AUTHOR "HEX9CF"
using namespace std;
int n, m;
int main()
{
set<int> S;
while (cin >> n >> m)
{
S.clear();
for (int j = 0; j < n + m; j++)
{
int in;
cin >> in;
S.insert(in);
}
for (set<int>::iterator it = S.begin(); it != S.end(); it++)
{
if (it != S.begin())
{
cout << " ";
}
cout << *it;
}
cout << endl;
}
return 0;
}