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;
}
本文介绍了一道简单的HDOJ题目——(A+B)问题,并使用C++标准模板库中的set来解决该问题。通过利用set的互异性特性(即集合中不允许存在重复元素),有效地完成了两个整数集合的并集操作。
607

被折叠的 条评论
为什么被折叠?



