Advertisement
JosepRivaille

X83904: Activitats esportives (sets)

Nov 3rd, 2015
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. void is_activity(set<string>& aa, set<string>& aux){
  8.   set<string>::iterator it = aa.begin();
  9.   while(it != aa.end()){
  10.     if(aux.find(*it) == aux.end()) it = aa.erase(it);
  11.     else ++it;
  12.   }
  13. }
  14.  
  15. void is_not_act(set<string>& na, set<string>& aux){
  16.   set<string>::iterator it = na.begin();
  17.   while(it != na.end()){
  18.     if(aux.find(*it) != aux.end()) it = na.erase(it);
  19.     else ++it;
  20.   }
  21. }
  22.  
  23. void write_output(set<string> aa, set<string> na){
  24.   set<string>::iterator it = aa.begin();
  25.   cout << "Totes les activitats:";
  26.   while(it != aa.end()){
  27.     cout << " " << *it;
  28.     ++it;
  29.   }
  30.   cout << endl;
  31.   it = na.begin();
  32.   cout << "Cap activitat:";
  33.   while(it != na.end()){
  34.     cout << " " << *it;
  35.     ++it;
  36.   }
  37.   cout << endl;
  38. }
  39.  
  40.  
  41. int main(){
  42.   set<string> aa;   // All activities
  43.   set<string> na;   // None activities
  44.   string s;
  45.   while(cin >> s and s != "."){
  46.     aa.insert(s);
  47.     na.insert(s);
  48.   }
  49.   int n;
  50.   cin >> n;
  51.   for(int i = 0; i < n; ++i){
  52.     set<string> aux;
  53.     while(cin >> s and s != ".") aux.insert(s);
  54.     is_activity(aa, aux);
  55.     is_not_act(na, aux);
  56.   }
  57.   write_output(aa, na);
  58. }
  59.  
  60. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement