Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <queue>
- #include <unordered_map>
- void populateMap( std::unordered_map<std::string, int> &inputMap,
- std::string& resource, int& value,
- std::queue<std::string>& inputQueue)
- {
- if(inputMap.find(resource)==inputMap.end())
- {
- inputQueue.push(resource);
- }
- inputMap[resource]+=value;
- }
- main(){
- std::unordered_map<std::string, int> inputMap;
- std::queue<std::string> inputQueue;
- std::string resource;
- int value;
- while(true)
- {
- std::cin>>resource;
- if(resource=="stop")
- {
- break;
- }
- std::cin>>value;
- populateMap(inputMap,resource ,value,inputQueue);
- }
- while(!inputQueue.empty())
- {
- std::string key=inputQueue.front();
- std::cout<< key <<" -> " <<
- inputMap[key] <<std::endl;
- inputQueue.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement