题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=3282
{A} + {B}
Description
给你两个集合,要求{A} + {B}.
注:同一个集合中不会有两个相同的元素.
Input
每组输入数据分为三行,第一行有两个数字$n,m(0 < n,m \leq 10000)$,分别表示集合A和集合B的元素个数.后两行分别表示集合A和集合B.每个元素为不超出int范围的整数,每个元素之间有一个空格隔开.
Output
针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出,每个元素之间有一个空格隔开.
SampleInput
1 2
1
2 3
1 2
1
1 2
SampleOutput
1 2 3
1 2
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<vector> 7 #include<map> 8 #include<set> 9 using std::cin; 10 using std::cout; 11 using std::endl; 12 using std::find; 13 using std::sort; 14 using std::set; 15 using std::map; 16 using std::pair; 17 using std::vector; 18 #define sz(c) (int)(c).size() 19 #define all(c) (c).begin(), (c).end() 20 #define iter(c) decltype((c).begin()) 21 #define cls(arr,val) memset(arr,val,sizeof(arr)) 22 #define cpresent(c, e) (find(all(c), (e)) != (c).end()) 23 #define rep(i, n) for (int i = 0; i < (int)(n); i++) 24 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i) 25 #define pb(e) push_back(e) 26 #define mp(a, b) make_pair(a, b) 27 const int Max_N = 100010; 28 typedef unsigned long long ull; 29 set<int> res; 30 int main() { 31 #ifdef LOCAL 32 freopen("in.txt", "r", stdin); 33 freopen("out.txt", "w+", stdout); 34 #endif 35 int n, m, v; 36 while (~scanf("%d %d", &n, &m)) { 37 rep(i, n + m) scanf("%d", &v), res.insert(v); 38 iter(res) it = res.begin(); 39 printf("%d", *it++); 40 for (; it != res.end(); ++it) printf(" %d", *it); 41 putchar(‘\n‘); 42 res.clear(); 43 } 44 return 0; 45 }
时间: 2024-11-23 20:23:07