HDOJ(HDU).1412 {A} + {B} (STL SET)

HDOJ(HDU).1412 {A} + {B} (STL SET)

点我挑战题目

题意分析

大水题,会了set直接用set即可。
利用的是set的互异性(同一元素有且仅有一项)。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define nmax 20005
using namespace std;
set<int> g;
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!= EOF){
        while(n--){int t;scanf("%d",&t); g.insert(t);}
        while(m--){int t;scanf("%d",&t); g.insert(t);}
        for(set<int>::iterator it = g.begin(); it!=g.end();++it){
            if(it == g.begin()) cout<<*it;
            else cout<<" "<<*it;
        }
        cout<<endl;
        g.clear();
    }
    return 0;
}
posted @ 2017-02-23 00:33  pengwill  阅读(129)  评论(0编辑  收藏  举报