Advertisement
Spocoman

07. Sets of Elements

Jan 21st, 2024
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int n, m, number;
  11.     cin >> n >> m;
  12.  
  13.     set<int> numbers1;
  14.     set<int> numbers2;
  15.  
  16.     for (int i = 0; i < n + m; i++) {
  17.         cin >> number;
  18.         i < n ? numbers1.insert(number) : numbers2.insert(number);
  19.     }
  20.  
  21.     vector<int> numbers3;
  22.     set_intersection(numbers1.begin(), numbers1.end(), numbers2.begin(), numbers2.end(), back_inserter(numbers3));
  23.  
  24.     for (auto& n : numbers3) {
  25.         cout << n << ' ';
  26.     }
  27.  
  28.     cout << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement