fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. void readSet(set<int>& v, istream_iterator<int>& input) {
  10. int size = *input++;
  11. while (size--) {
  12. v.insert(*input++);
  13. }
  14. }
  15.  
  16. int main() {
  17. istream_iterator<int> input(cin);
  18. set<int> a, b;
  19. readSet(a, input);
  20. readSet(b, input);
  21.  
  22. set<int> intersection;
  23. set_intersection(
  24. a.begin(), a.end(),
  25. b.begin(), b.end(),
  26. inserter(intersection, intersection.end())
  27. );
  28.  
  29. cout << "Ilosc powtarzajacych sie: " << intersection.size() << "\n";
  30. cout << "Liczby:\n";
  31. copy(
  32. intersection.begin(),
  33. intersection.end(),
  34. ostream_iterator<int>(cout, "\n")
  35. );
  36. return 0;
  37. }
Success #stdin #stdout 0s 3036KB
stdin
4

11 22 33 44

3

11 222 22
stdout
Ilosc powtarzajacych sie: 2
Liczby:
11
22