Advertisement
Spocoman

07. Miners

Jan 26th, 2024
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <list>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     string resource;
  11.     getline(cin, resource);
  12.  
  13.     list<pair<string, int>> resources;
  14.  
  15.     int quantity;
  16.  
  17.     while (resource != "stop") {
  18.         cin >> quantity;
  19.         bool isresource = false;
  20.  
  21.         for (auto& r : resources) {
  22.             if (r.first == resource) {
  23.                 r.second += quantity;
  24.                 isresource = true;
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         if (!isresource) {
  30.             resources.push_back(make_pair(resource, quantity));
  31.         }
  32.  
  33.         cin.ignore();
  34.         getline(cin, resource);
  35.     }
  36.  
  37.     for (auto &r : resources) {
  38.             cout << r.first << " -> " << r.second << endl;
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement