Advertisement
Spocoman

01. Shopping List

Feb 4th, 2024
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     cin.ignore();
  12.  
  13.     double totalSum = 0;
  14.  
  15.     string product, price, count;
  16.  
  17.     vector<pair<string, double>> productPrices;
  18.  
  19.     for (size_t i = 0; i < n; i++) {
  20.         getline(cin, product);
  21.         getline(cin, price);
  22.         getline(cin, count);
  23.  
  24.         productPrices.push_back(make_pair(product, stod(price) * stoi(count)));
  25.         totalSum += productPrices.rbegin()->second;
  26.     }
  27.  
  28.     sort(productPrices.begin(), productPrices.end(),
  29.         [](const pair <string, double>& a, const pair <string, double>& b) {
  30.             return a.second > b.second;
  31.         });
  32.  
  33.     cout << "The total sum is: " << totalSum << " lv.\n";
  34.  
  35.     for (auto& p : productPrices) {
  36.         cout << p.first << ' ' << p.second << endl;
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement