{A} + {B}
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21951 Accepted Submission(s): 9050
Problem Description
给你两个集合,要求{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
Sample Output
1 2 3 1 2
Author
xhd
Source
Recommend
lxj | We have carefully selected several similar problems for you: 1408 1720 1407 1229 1431
#include<iostream>
#include<set>
using namespace std;
int main()
{
int a,b,m;
while(cin>>a>>b)
{
set <int> s;
set<int>::iterator str;
for(int i=0;i<a;i++)
{
scanf("%d",&m);
s.insert(m);
}
for(int i=0;i<b;i++)
{
scanf("%d",&m);
s.insert(m);
}
for(str=s.begin();str!=s.end();str++)
{
if(str==s.begin())
cout<<*str;
else
cout<<" "<<*str;
}
cout<<endl;
}
return 0;
}
这个代码有一点不规范,我写的时候忘了,应该把s先清0的