{A} + {B}
Problem : 1412 ( {A} + {B} ) Judge Status : Accepted
RunId : 2507648 Language : G++ Author : luxiuyuan
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
Problem Description
給你兩個集合,要求{A} + {B}.
注:同一個集合中不會有兩個相同的元素.
Input
每組輸入數據分為三行,第一行有兩個數字n,m(0<n,m<=10000),分別表示集合A和集合B的元素個數.后兩行分別表示集合A和集合B.每個元素為不超出int范圍的整數,每個元素之間有一個空格隔開.
Output
針對每組數據輸出一行數據,表示合并后的集合,要求從小到大輸出,每個元素之間有一個空格隔開.
Sample Input
Sample Output
1 2 3
1 2
呵呵~~這是一個簡單的問題:
1 #include<iostream>
2 using namespace std;
3 int main(){
4 int a[20003];
5 int n,m;
6 while (cin>>n>>m)
7 {
8 memset(a,0,sizeof(a));
9 int i=0,j=0;
10 for (i=0;i<n;i++)
11 cin>>a[i];
12 for (j=0;j<m;i++,j++)
13 cin>>a[i];
14 sort(a,a+i);
15 int f = 0;
16 for (j=0;j<i;j++)
17 {
18 if(a[j]==a[j+1])continue;
19 if(a[j]!=a[j+1]) f++;
20 if(f>1)cout<<' ';
21 cout<<a[j];
22 }
23 cout<<endl;
24 }
25 return 0;
26 }
27
posted on 2010-06-11 10:15
路修遠 閱讀(1573)
評論(0) 編輯 收藏 引用