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

时间:2023-03-08 17:18:39
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;
}