Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <list>
- #include <cmath>
- #include <algorithm>
- #include <map>
- #include <set>
- using namespace std;
- class Sale {
- std::string m_town, m_product = "";
- double m_price = 0.0;
- int m_quantity = 0;
- public:
- Sale();
- Sale(std::string &town, std::string &product, double &price, int &quantity) {
- m_town = town;
- m_product = product;
- m_price = price;
- m_quantity = quantity;
- }
- std::string getTownName() const {
- return m_town;
- }
- double sumProduct() {
- return m_price * m_quantity;
- }
- bool operator< (const Sale &right) const {
- return m_town < right.m_town;
- }
- bool operator== (const Sale &right) const {
- return this->m_town == right.m_town;
- }
- };
- int main() {
- int numCities = 0;
- std::string town = "";
- std::string product = "";
- double price = 0.0;
- int quantity = 0;
- std::vector<Sale> saleV;
- std::set<Sale> saleS;
- cout.setf(ios::fixed);
- cout.precision(2);
- cin.setf(ios::fixed);
- cin.precision(2);
- cin >> numCities;
- while(std::cin >> town && std::cin >> product && std::cin >> price && std::cin >> quantity && numCities != 0) {
- Sale s(town, product, price, quantity);
- saleV.push_back(s);
- saleS.insert(s);
- --numCities;
- if(numCities == 0) {
- break;
- }
- }
- double sum = 0.0;
- //sort(saleV.begin(), saleV.end());
- for(auto it = saleS.begin(); it != saleS.end(); ++it) {
- std::string temp = it->getTownName();
- std::vector<Sale>::iterator iter = saleV.begin();
- sum = 0.0;
- while((iter = std::find(iter, saleV.end(), *it)) != saleV.end())
- {
- sum += iter->sumProduct();
- iter++;
- }
- cout << it->getTownName() << " -> " << sum;
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement