Advertisement
yejolga

ol2_5 //in_progress

Feb 11th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <utility>
  5. #include <algorithm>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. bool firsteq(const pair <string, string> &a, const pair <string, string> &b)
  11. {
  12.     return (a.first != b.first);
  13. }
  14.  
  15. int main()
  16. {
  17.     ifstream cin("input.txt");
  18.  
  19.     int n;
  20.     cin>>n;
  21.     vector<pair<string, string>>vin, vout, vboth;
  22.     string name, io;
  23.     for(int i = 0; i < n; i++)
  24.     {
  25.         cin>>name;
  26.         cin>>io;
  27.         if(io == "in")
  28.             vin.push_back({name, io});
  29.         else
  30.             vout.push_back({name, io});
  31.     }
  32.  
  33.     sort(vin.begin(), vin.end());
  34.     auto inlast = unique(vin.begin(), vin.end());
  35.     vin.erase(inlast, vin.end());
  36.  
  37.     sort(vout.begin(), vout.end());
  38.     auto outlast = unique(vout.begin(), vout.end());
  39.     vout.erase(outlast, vout.end());
  40.  
  41.     set_intersection(vin.begin(), vin.end(), vout.begin(), vout.end(), back_inserter(vboth)
  42.                      , firsteq
  43.                      );
  44.     vector<pair<string, string>> vin1, vout1;
  45.     set_difference(vin.begin(), vin.end(), vboth.begin(), vboth.end(), back_inserter(vin1)
  46.                      , firsteq
  47.                      );
  48.     set_difference(vout.begin(), vout.end(), vboth.begin(), vboth.end(), back_inserter(vout1)
  49.                      , firsteq
  50.                      );
  51.     for(auto vi : vboth) cout<<vi.first<<' ';
  52.     cout<<endl;
  53.     for(auto vi : vin1) cout<<vi.first<<' ';
  54.     cout<<endl;
  55.     for(auto vi : vout1) cout<<vi.first<<' ';
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement