题解 | #整型数组合并#
整型数组合并
https://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
使用while嵌套cin读取,保证后续输出成功
利用set进行排序+去重
#include <algorithm> #include <functional> #include <iostream> #include <set> using namespace std; int main() { int len1, len2 = 0; set<int> new_vec; while (cin >> len1) { // cin >> len1; // vector<int> vec1; for (int i = 0; i < len1; i ++) { int num = 0; cin >> num; // vec1.push_back(num); new_vec.insert(num); } cin >> len2; // vector<int> vec2; for (int i = 0; i < len2; i ++) { int num = 0; cin >> num; // vec2.push_back(num); new_vec.insert(num); } for(auto it = new_vec.begin(); it != new_vec.end(); it++) cout << *it; cout<<endl; } } // // 64 位输出请用 printf("%lld")