{A} + {B}
给你两个集合,要求{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 2Sample Output
1 2 3 1 2
题意:合并两个集合
思路:set容器。
坑点:输出的最后一个数字后不能带空格
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
int main()
{
int n,m,x,flag;
while(scanf("%d%d",&n,&m)!=EOF){
set<int> s;
int k=0;
for(int i=1;i<=n+m;++i){
scanf("%d",&x);
s.insert(x);
}
set<int>::iterator it;
flag=0;
for(it=s.begin();it!=s.end();++it){
if(flag==0){
cout<<*it;
flag=1;
}
else
cout<<" "<<*it;
}
cout<<endl;
}
return 0;
}