JosepRivaille

P40902: Casino

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