SHARE
TWEET

7. Miners

a guest Oct 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include <iostream>
  2. #include <map>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     map<string, int> mines;
  10.     queue<string> order;
  11.     while (true)
  12.     {
  13.         string resource;
  14.         cin >> resource;
  15.         if (resource == "stop")
  16.         {
  17.             break;
  18.         }
  19.  
  20.         int quantity;
  21.         cin >> quantity;
  22.        
  23.         if (mines.find(resource) == mines.end())
  24.         {
  25.             order.push(resource);
  26.         }
  27.  
  28.         mines[resource] += quantity;
  29.     }
  30.  
  31.     while (!order.empty())
  32.     {
  33.         string element = order.front();
  34.         cout << element << " -> " << mines[element] << endl;
  35.         order.pop();
  36.     }
  37.  
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top