hdu 1412 {A} + {B}

{A} + {B}

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


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 <stack>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;
/**/
#define ms(arr, val) memset(arr, val, sizeof(arr))
#define N 10005
#define INF 0x3fffffff
#define vint vector<int>
#define sint set<int>

sint s;
int main()
{
    int  n, m;
    int t;
    while (cin >> n >> m)
    {
        s.clear();
        for (int i = 0; i < n + m; i++)
        {
            cin >> t;
            s.insert(t);
        }

        for (sint::iterator it = s.begin(); it != --s.end(); it++)
        {
            cout << *it <<' ';
        }
        cout << *(--s.end()) << endl;
    }
    return 0;
}

 

posted on 2014-08-07 16:42  jec  阅读(152)  评论(0编辑  收藏  举报

导航