Advertisement
cska1312

07. Miners

May 11th, 2023
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   vector<string> resources;
  10.   unordered_map<string, int> Quantity;
  11.  
  12.   string resource;
  13.   while (cin >> resource && resource != "stop")
  14.   {
  15.     if (Quantity.find(resource) == Quantity.end())
  16.     {
  17.       resources.emplace_back(resource);
  18.       Quantity.emplace(resource, 0);
  19.     }
  20.  
  21.     int quantity;
  22.     cin >> quantity;
  23.     Quantity[resource] += quantity;
  24.   }
  25.  
  26.   for (const auto &item : resources)
  27.   {
  28.     const auto& it = Quantity.find(item);
  29.     cout << it->first << " -> " << it->second << endl;
  30.   }
  31.  
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement