mstoyanov7

07. Miners

Jun 4th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <map>
  6. #include <queue>
  7. #include <algorithm>
  8. #include <utility>
  9.  
  10. void readInput(std::map<std::string, int>& resources, std::vector<std::string>& commands) {
  11. std::string command;
  12. int quantity;
  13. std::cin >> command;
  14.  
  15. while (true) {
  16. if (command == "stop") {
  17. break;
  18. }
  19.  
  20. if (!(std::find(commands.begin(), commands.end(), command) != commands.end())) {
  21. commands.push_back(command);
  22. continue;
  23. }
  24.  
  25. resources[command];
  26. std::cin >> quantity;
  27.  
  28. resources[command] += quantity;
  29.  
  30. std::cin >> command;
  31. }
  32. }
  33.  
  34.  
  35.  
  36. void printResources(std::map<std::string, int>& resources, std::vector<std::string> commands) {
  37. for (int i = 0; i < commands.size(); ++i) {
  38. std::cout << commands[i] << " -> " << resources[commands[i]] << std::endl;
  39. }
  40. }
  41.  
  42. int main() {
  43. std::map<std::string, int> resources;
  44.  
  45. std::vector<std::string> commands;
  46.  
  47. readInput(resources, commands);
  48.  
  49. printResources(resources, commands);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment