Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <sstream>
- using namespace std;
- int main ()
- {
- int numberOfSales;
- cin >> numberOfSales;
- cin.ignore();
- map <string, double> citySales;
- string input, tempStr, city;
- double price, quantity, money;
- while (numberOfSales != 0)
- {
- getline (cin, input);
- istringstream istr (input);
- for (int i = 0; i < 4; ++i)
- {
- cycle: istr >> tempStr;
- if (i == 0)
- {
- city = tempStr;
- } else if (i == 1)
- {
- ++i;
- goto cycle;
- } else if (i == 2)
- {
- price = stod (tempStr);
- } else
- {
- quantity = stod (tempStr);
- }
- }
- money = price * quantity;
- if (citySales.find (city) == citySales.end())
- {
- citySales.insert(pair <string, double> {city, money});
- } else
- {
- citySales [city] += money;
- }
- numberOfSales--;
- }
- map <string, double>::iterator it = citySales.begin();
- cout.setf(ios::fixed);
- cout.precision(2);
- for (it; it != citySales.end(); it++)
- {
- cout << it -> first << " -> " << it -> second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement