Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <utility>
- #include <algorithm>
- using namespace std;
- bool firsteq(const pair <string, string> &a, const pair <string, string> &b)
- {
- return (a.first != b.first);
- }
- int main()
- {
- ifstream cin("input.txt");
- int n;
- cin>>n;
- vector<pair<string, string>>vin, vout, vboth;
- string name, io;
- for(int i = 0; i < n; i++)
- {
- cin>>name;
- cin>>io;
- if(io == "in")
- vin.push_back({name, io});
- else
- vout.push_back({name, io});
- }
- sort(vin.begin(), vin.end());
- auto inlast = unique(vin.begin(), vin.end());
- vin.erase(inlast, vin.end());
- sort(vout.begin(), vout.end());
- auto outlast = unique(vout.begin(), vout.end());
- vout.erase(outlast, vout.end());
- set_intersection(vin.begin(), vin.end(), vout.begin(), vout.end(), back_inserter(vboth)
- , firsteq
- );
- vector<pair<string, string>> vin1, vout1;
- set_difference(vin.begin(), vin.end(), vboth.begin(), vboth.end(), back_inserter(vin1)
- , firsteq
- );
- set_difference(vout.begin(), vout.end(), vboth.begin(), vboth.end(), back_inserter(vout1)
- , firsteq
- );
- for(auto vi : vboth) cout<<vi.first<<' ';
- cout<<endl;
- for(auto vi : vin1) cout<<vi.first<<' ';
- cout<<endl;
- for(auto vi : vout1) cout<<vi.first<<' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement