Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <map>
- #include <queue>
- #include <algorithm>
- #include <utility>
- void readInput(std::map<std::string, int>& resources, std::vector<std::string>& commands) {
- std::string command;
- int quantity;
- std::cin >> command;
- while (true) {
- if (command == "stop") {
- break;
- }
- if (!(std::find(commands.begin(), commands.end(), command) != commands.end())) {
- commands.push_back(command);
- continue;
- }
- resources[command];
- std::cin >> quantity;
- resources[command] += quantity;
- std::cin >> command;
- }
- }
- void printResources(std::map<std::string, int>& resources, std::vector<std::string> commands) {
- for (int i = 0; i < commands.size(); ++i) {
- std::cout << commands[i] << " -> " << resources[commands[i]] << std::endl;
- }
- }
- int main() {
- std::map<std::string, int> resources;
- std::vector<std::string> commands;
- readInput(resources, commands);
- printResources(resources, commands);
- }
Advertisement
Add Comment
Please, Sign In to add comment