Advertisement
bobo_bobkata

Untitled

Oct 24th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. #include <sstream>
  5. #include <cmath>
  6. #include <list>
  7. #include <map>
  8.  
  9. int main() {
  10. std::map<std::string, double > map;
  11. std::vector<std::string> ordered;
  12. while (true) {
  13.  
  14. std::string input;
  15. std::getline(std::cin, input);
  16. if (input == "stop") {
  17. break;
  18. }
  19. bool contains = false;
  20. for (int i = 0; i < ordered.size(); ++i) {
  21. if (ordered[i] == input) {
  22. contains = true;
  23. }
  24. }
  25. if (!contains) {
  26. ordered.push_back(input);
  27. }
  28. std::string numberToStr;
  29. std::getline(std::cin, numberToStr);
  30. double number = std::stod(numberToStr);
  31. bool isThere = false;
  32. for (std::pair<std::string, double> element : map) {
  33. if (element.first == input) {
  34. isThere = true;
  35. break;
  36. }
  37. }
  38. if (!isThere) {
  39. map.insert(std::pair<std::string, double>(input, number));
  40. } else {
  41. double currentNumber = map[input];
  42. double sum = number + currentNumber;
  43. map[input] = sum;
  44. }
  45. }
  46. for (int i = 0; i < ordered.size(); ++i) {
  47. std::string current = ordered[i];
  48. ordered.erase(ordered.begin());
  49. i--;
  50.  
  51. std::cout.setf(std::ios::fixed);
  52. std::cout.precision(0);
  53. for (std::pair<std::string, double> element : map) {
  54. if (element.first == current) {
  55. std::cout << element.first << " -> " << element.second << std::endl;
  56. }
  57. }
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement