Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <queue>
  4. #include <unordered_map>
  5.  
  6.  
  7. void populateMap( std::unordered_map<std::string, int> &inputMap,
  8.                  std::string& resource, int& value,
  9.                  std::queue<std::string>& inputQueue)
  10. {
  11.     if(inputMap.find(resource)==inputMap.end())
  12.     {
  13.         inputQueue.push(resource);
  14.     }
  15.     inputMap[resource]+=value;
  16.  
  17.  
  18.  
  19. }
  20.  
  21. main(){
  22.  
  23.     std::unordered_map<std::string, int> inputMap;
  24.     std::queue<std::string> inputQueue;
  25.  
  26.     std::string resource;
  27.  
  28.     int value;
  29.  
  30.     while(true)
  31.     {
  32.         std::cin>>resource;
  33.         if(resource=="stop")
  34.         {
  35.             break;
  36.         }
  37.         std::cin>>value;
  38.         populateMap(inputMap,resource ,value,inputQueue);
  39.  
  40.     }
  41.  
  42.     while(!inputQueue.empty())
  43.     {
  44.             std::string key=inputQueue.front();
  45.            
  46.             std::cout<< key <<" -> " <<
  47.              inputMap[key] <<std::endl;
  48.              inputQueue.pop();
  49.     }
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement