Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iterator>
- #include <sstream>
- #include <cmath>
- #include <list>
- #include <map>
- int main() {
- std::map<std::string, double > map;
- std::vector<std::string> ordered;
- while (true) {
- std::string input;
- std::getline(std::cin, input);
- if (input == "stop") {
- break;
- }
- bool contains = false;
- for (int i = 0; i < ordered.size(); ++i) {
- if (ordered[i] == input) {
- contains = true;
- }
- }
- if (!contains) {
- ordered.push_back(input);
- }
- std::string numberToStr;
- std::getline(std::cin, numberToStr);
- double number = std::stod(numberToStr);
- bool isThere = false;
- for (std::pair<std::string, double> element : map) {
- if (element.first == input) {
- isThere = true;
- break;
- }
- }
- if (!isThere) {
- map.insert(std::pair<std::string, double>(input, number));
- } else {
- double currentNumber = map[input];
- double sum = number + currentNumber;
- map[input] = sum;
- }
- }
- for (int i = 0; i < ordered.size(); ++i) {
- std::string current = ordered[i];
- ordered.erase(ordered.begin());
- i--;
- std::cout.setf(std::ios::fixed);
- std::cout.precision(0);
- for (std::pair<std::string, double> element : map) {
- if (element.first == current) {
- std::cout << element.first << " -> " << element.second << std::endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement