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

11 22 33 44

3

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