1 #include <bits/stdc++.h> 2 using namespace std; 3 vector<int> a; 4 vector<int> b; 5 vector<int> c; 6 void Print(vector<int> &c){ 7 for (int i = 0; i < c.size(); i++) { 8 cout << c[i] << " "; 9 } 10 cout << endl; 11 c.clear(); 12 } 13 int main(){ 14 int m, n, temp; 15 cin >> m; 16 for (int i = 0; i < m; i++){ 17 cin >> temp; 18 a.push_back(temp); 19 } 20 cin >> n; 21 for (int i = 0; i < n; i++){ 22 cin >> temp; 23 b.push_back(temp); 24 } 25 sort(a.begin(), a.end()); 26 sort(b.begin(), b.end()); 27 set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c)); 28 Print(c); 29 set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c)); 30 Print(c); 31 set_difference(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c)); 32 Print(c); 33 return 0; 34 }
原文:https://www.cnblogs.com/fx1998/p/12700089.html