HDU-1412 {A} + {B}

http://acm.hdu.edu.cn/showproblem.php?pid=1412

{A} + {B}

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9663    Accepted Submission(s): 4002

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
 
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 #define M 20000
 5 int c[M];
 6 int main()
 7 {
 8  int n,m;
 9  int a,b;
10  int i;
11  while(cin>>n>>m)
12  {
13   int k=0;
14   for(i=0;i<n;i++)
15   {
16    cin>>a;
17    c[k++]=a;
18   }
19   for(i=0;i<m;i++)
20   {
21    cin>>b;
22    c[k++]=b;
23   }
24   sort(c,c+k);
25   for(i=0;i<k;i++)
26   {
27    if(c[i]!=c[i+1])
28    {
29     cout<<c[i];
30     if(i!=k-1)
31      cout<<" ";
32    }
33   }
34   cout<<endl;
35  }
36  return 0;
37 }
38  

posted @ 2013-10-21 21:11  疯狂的癫子  阅读(186)  评论(0编辑  收藏  举报