Advertisement
Guest User

Untitled

a guest
Oct 28th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int main ()
  10. {
  11.  
  12. int numberOfSales;
  13. cin >> numberOfSales;
  14. cin.ignore();
  15.  
  16.  
  17. map <string, double> citySales;
  18.  
  19. string input, tempStr, city;
  20. double price, quantity, money;
  21.  
  22. while (numberOfSales != 0)
  23. {
  24.     getline (cin, input);
  25.     istringstream istr (input);
  26.  
  27.      for (int i = 0; i < 4; ++i)
  28.     {
  29.         cycle: istr >> tempStr;
  30.  
  31.         if (i == 0)
  32.         {
  33.             city = tempStr;
  34.         } else if (i == 1)
  35.         {
  36.             ++i;
  37.             goto cycle;
  38.  
  39.         } else if (i == 2)
  40.         {
  41.             price = stod (tempStr);
  42.         } else
  43.         {
  44.             quantity = stod (tempStr);
  45.         }
  46.     }
  47.  
  48.     money = price * quantity;
  49.  
  50.     if (citySales.find (city) == citySales.end())
  51.     {
  52.         citySales.insert(pair <string, double> {city, money});
  53.     } else
  54.     {
  55.         citySales [city] += money;
  56.     }
  57.  
  58.     numberOfSales--;
  59. }
  60.  
  61. map <string, double>::iterator it = citySales.begin();
  62.  
  63. cout.setf(ios::fixed);
  64. cout.precision(2);
  65.  
  66. for (it; it != citySales.end(); it++)
  67. {
  68.     cout << it -> first << " -> " << it -> second << endl;
  69. }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement