Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- using namespace std;
- set<int> convert(string s)
- {
- set<int> a;
- s.erase(0, 1);
- while(s.length())
- {
- int punc = min(s.find(','), s.find(']'));
- string littles = s.substr(0, punc);
- a.insert(stoi(littles));
- s.erase(s.begin(), s.begin() + punc + 1);
- }
- return a;
- }
- void print(set<int> a)
- {
- cout << "[";
- int counter = 0;
- for(set<int>::iterator i = a.begin(); i != a.end(); i++)
- {
- counter++;
- cout << *i;
- if (counter < a.size())
- cout << ",";
- }
- cout << "]\n";
- }
- int main()
- {
- string A, B;
- cin >> A >> B;
- set<int> a, b, intersection, association, difference;
- a = convert(A);
- b = convert(B);
- for(set<int>::iterator i = a.begin(); i != a.end(); i++)
- {
- if (b.count(*i))
- intersection.insert(*i);
- else
- difference.insert(*i);
- association.insert(*i);
- }
- for(set<int>::iterator i = b.begin(); i != b.end(); i++)
- {
- association.insert(*i);
- }
- print(intersection);
- print(association);
- print(difference);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement