Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- vector<pair<string, int>> result;
- string input;
- cin >> input;
- int number = INT_MIN;
- string metal = "";
- while (input != "stop") {
- if (input[0] >= '1' && input[0] <= '9') {
- number = stoi(input);
- } else {
- metal = input;
- }
- if (metal.length() > 0 && number != INT_MIN) {
- auto it = find_if(result.begin(), result.end(), [&](const pair<string, int>& p) { return p.first == metal; });
- if (it != result.end()) {
- it->second += number;
- } else {
- result.emplace_back(metal, number);
- }
- number = INT_MIN;
- metal = "";
- }
- cin >> input;
- }
- for (auto& it : result) {
- cout << it.first << " -> " << it.second << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement