vardgrig

bilet2/3

Dec 1st, 2021 (edited)
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <algorithm>
  5. #include <iterator>
  6.  
  7. std::set<int> intersection(std::set<int> &s1, std::set<int> &s2) {
  8.     std::set<int> i;
  9.     std::set<int> inter;
  10.     set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),std::inserter(inter, inter.begin()));
  11.     return inter;
  12. }
  13.  
  14. int main() {
  15.     std::set<int> i1;
  16.     std::set<int> i2;
  17.     std::set<int>::iterator it;
  18.     i1.insert(1);
  19.     i1.insert(5);
  20.     i1.insert(9);
  21.     i1.insert(14);
  22.     i2.insert(5);
  23.     i2.insert(4);
  24.     i2.insert(11);
  25.     i2.insert(9);
  26.     std::set<int> result = intersection(i1, i2);
  27.     for (it = result.begin(); it != result.end(); ++it) std::cout << *it << " ";
  28. }
RAW Paste Data