Advertisement
JosepRivaille

P60219: Easy game?

Mar 7th, 2016
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5.  
  6. struct strsize{
  7.   bool operator() (const string& a, const string& b) const {
  8.     if (a.size() < b.size()) return true;
  9.     else if (a.size() > b.size()) return false;
  10.     else return a < b;
  11.   }
  12. };
  13.  
  14. int main() {
  15.   int count = 1;
  16.   string s;
  17.   set<string>::iterator it1;
  18.   set<string, strsize>::iterator it2;
  19.   while (s != "QUIT") {
  20.     set<string> has;
  21.     set<string,strsize> had;
  22.     while (cin >> s && s != "END" && s != "QUIT") {
  23.       it1 = has.find(s);
  24.       if (it1 == has.end()) {
  25.     has.insert(it1,s);
  26.     it2 = had.find(s);
  27.     if (it2 != had.end()) had.erase(it2);
  28.       }
  29.       else {
  30.     it2 = had.begin();
  31.     had.insert(it2,*it1);
  32.     has.erase(it1);
  33.       }
  34.     }
  35.     if (count > 1) cout << endl;
  36.     cout << "GAME #" << count << endl << "HAS:" << endl;
  37.     for (it1 = has.begin(); it1 != has.end(); ++it1) cout << *it1 << endl;
  38.     cout << endl << "HAD:" << endl;
  39.     for (it2 = had.begin(); it2 != had.end(); ++it2) cout << *it2 << endl;
  40.     ++count;
  41.   }
  42. }
  43.  
  44. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement