Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <vector>
- #include <map>
- #include <set>
- #include <functional>
- using namespace std;
- class Product{
- public : Product(string cfc, string ctc, string c, string n){
- country_from_code = cfc;
- country_to_code = ctc;
- code = c;
- num = n;
- }
- public : string country_from_code;
- public : string country_to_code;
- public : string code;
- public : string num;
- public : bool check(string abbr){
- return *country_from_code.begin() == *abbr.begin() &&
- *country_to_code.begin() == *(abbr.begin()+1) &&
- *code.begin() == *(abbr.begin()+2);
- }
- public : string get_str_code(){
- return this->country_from_code + " " + this->country_to_code + " " + this->code;
- }
- };
- int main()
- {
- vector<Product> products = {
- *(new Product("FR742", "BEL1254", "TR4587", "1236547")),
- *(new Product("RU1254", "FR4567", "GT12454", "1236548")),
- *(new Product("FR654", "GER4526", "LK1245", "1236549")),
- *(new Product("FR742", "BEL1254", "TR4587", "1236550")),
- *(new Product("FIN1254", "BUL252", "TW1247", "1236551"))
- };
- map<string, int> m;
- for (auto& p : products)
- if (p.check("FBT") && m.find(p.get_str_code()) == m.end())
- m.insert(make_pair(p.get_str_code(), 1));
- else
- (m.find(p.get_str_code()))->second++;
- typedef function<bool(pair<string, int>, pair<string, int>)> Comparator;
- Comparator compFunctor =
- [](pair<string, int> elem1, pair<string, int> elem2)
- {
- return elem1.second > elem2.second;
- };
- set<pair<string, int>, Comparator> s(
- m.begin(), m.end(), compFunctor);
- for (auto& p : s)
- cout << p.first << " " << p.second << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement