Advertisement
myloyo

set4

Jun 7th, 2023 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <string>
  6. #include <fstream>
  7. #include <sstream>
  8. #include <set>
  9.  
  10. using namespace std;
  11. ifstream in("input.txt");
  12. ofstream out("output.txt");
  13.  
  14. int main() {
  15.     set <int> chet;
  16.     set <int> nechet;
  17.     string s;
  18.     int f = 0;
  19.     int k;
  20.     while (getline(in, s)) {
  21.         stringstream sin(s);
  22.         while (sin >> k) {
  23.             if (f % 2 == 0) {
  24.                 chet.insert(k);
  25.             }
  26.             else {
  27.                 nechet.insert(k);
  28.             }
  29.         }
  30.         f++;
  31.     }
  32.  
  33.     for (auto it : nechet) {
  34.         chet.erase(it);
  35.     }
  36.  
  37.     for (auto it : chet) {
  38.         out << it << " ";
  39.     }
  40. }
  41.  
  42.  
  43. 455  455
  44. 455
  45. 2121
  46. 0
  47. 666 33 288
  48. 3100
  49. 555
  50. 555 555
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement