HDU412{A} + {B}(STL)

{A} + {B}

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

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

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int main()
{
    int n, m, v;
    set<int> r;
    while(cin >> n >> m) {
        r.clear();
        for(int i=1; i<=n+m; i++) {
            cin>> v;
            r.insert(v);
        }
        int k = 1;
        for(set<int>::iterator it = r.begin(); it != r.end(); it++) {
            if(k==0){
             	cout << " ";
			}   
            k = 0;
            cout<<*it;
        }
        cout<<endl;
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章