Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- cin.ignore();
- double totalSum = 0;
- string product, price, count;
- vector<pair<string, double>> productPrices;
- for (size_t i = 0; i < n; i++) {
- getline(cin, product);
- getline(cin, price);
- getline(cin, count);
- productPrices.push_back(make_pair(product, stod(price) * stoi(count)));
- totalSum += productPrices.rbegin()->second;
- }
- sort(productPrices.begin(), productPrices.end(),
- [](const pair <string, double>& a, const pair <string, double>& b) {
- return a.second > b.second;
- });
- cout << "The total sum is: " << totalSum << " lv.\n";
- for (auto& p : productPrices) {
- cout << p.first << ' ' << p.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement