0
点赞
收藏
分享

微信扫一扫

HDU - {A} + {B}(STL)

仲秋花似锦 2022-02-03 阅读 70


题目链接:​​​http://acm.hdu.edu.cn/showproblem.php?pid=1412​​​

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

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


Problem solving report:

Description: 给你两个集合,求出没有重复元素的{A} + {B}. 

Problem solving: 利用STL里面的set的特性(没有重复元素)。

Accepted Code:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
char str[20];
while (~scanf("%d%d", &n, &m)) {
set <int> spt;
for (int i = 0; i < n + m; i++) {
scanf("%d", &a);
spt.insert(a);
}
set <int>::iterator it;
for (it = spt.begin(); it != spt.end(); it++) {
if (it != spt.begin())
printf(" %d", *it);
else printf("%d", *it);
}
printf("\n");
}
return 0;
}


举报

相关推荐

0 条评论