fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4. #include <unordered_set>
  5. #include <algorithm>
  6.  
  7. int main() {
  8. std::vector<int> a = {1,2,3,4,5,5};
  9. std::vector<int> b = {5,5,5,5,4};
  10. std::vector<int> c;
  11. std::unordered_set<int> t(a.begin(), a.end());
  12.  
  13. for (auto &x : b) {
  14. auto it = t.find(x);
  15. if (it != t.end()) {
  16. c.push_back(x);
  17. t.erase(it);
  18. }
  19. }
  20.  
  21. for (auto &x : c) {
  22. std::cout << x << std::endl;
  23. }
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
5
4