Advertisement
Spocoman

03. Products and Cities(90/100)

Feb 6th, 2024 (edited)
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.  
  11.     map<string, double> cities;
  12.  
  13.     while (true) {
  14.         cin.ignore();
  15.  
  16.         string city;
  17.         getline(cin, city);
  18.        
  19.         city.erase(city.find_last_not_of(' ') + 1);
  20.  
  21.         if (city.empty()) {
  22.             break;
  23.         }
  24.  
  25.         double price;
  26.         int quantity;
  27.  
  28.         cin >> price >> quantity;
  29.         cities[city] += price * quantity;
  30.     }
  31.  
  32.     for (auto& c : cities) {
  33.         cout << c.first << ' ' << c.second << endl;
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement