Advertisement
JosepRivaille

P84415: La bossa de les paraules

Feb 18th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6.   string action, word;
  7.   map<string,int> M;
  8.   map<string,int>::iterator it;
  9.   while (cin >> action) {
  10.     if (action == "store") {
  11.       cin >> word;
  12.       it = M.find(word);
  13.       if (it == M.end()) M.insert(make_pair(word, 1));
  14.       else it->second += 1;
  15.     }
  16.     else if (action == "delete") {
  17.       cin >> word;
  18.       it = M.find(word);
  19.       if (it != M.end()) {
  20.     if (it->second > 1) it->second -= 1;
  21.     else M.erase(it);
  22.       }
  23.     }
  24.     else if (action == "minimum?") {
  25.       if (M.empty()) cout << "indefinite minimum" << endl;
  26.       else {
  27.     cout << "minimum: " << M.begin()->first << ", " << M.begin()->second << " time(s)" << endl;
  28.       }
  29.     }
  30.     else { //"maximum?"
  31.       if (M.empty()) cout << "indefinite maximum" << endl;
  32.       else {
  33.     it = M.end();
  34.     --it;
  35.     cout << "maximum: " << it->first << ", " << it->second << " time(s)" << endl;
  36.       }
  37.     }
  38.   }
  39. }
  40.  
  41. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement