Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <set>
- #include <map>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <vector>
- #include <cmath>
- using namespace std;
- struct dev
- {
- long long sell;
- long long sc;
- };
- bool operator< (dev p1, dev p2)
- {
- if (p1.sc == p2.sc)
- return p1.sell < p2.sc;
- else
- return p1.sc < p2.sc;
- }
- int main()
- {
- string s, max;
- map <string, dev> product;
- long long maxsc=-1, maxsell=-1;
- while (cin >> s)
- {
- string prom;
- int prom2;
- cin >> prom;
- cin >> prom2;
- if (product.find(prom) != product.end())
- {
- if (product[prom].sell > prom2)
- product[prom].sell = prom2;
- product[prom].sc++;
- }
- else
- {
- dev prom3;
- prom3.sell = prom2;
- prom3.sc = 1;
- product.insert(pair <string, dev>(prom, prom3));
- }
- }
- for (auto i = product.begin(); i != product.end(); i++)
- {
- if (i->second.sc > maxsc)
- {
- max = i->first;
- maxsc = i->second.sc;
- maxsell = i->second.sell;
- }
- else
- if (i->second.sc == maxsc)
- if (i->second.sell < maxsell)
- {
- max = i->first;
- maxsc = i->second.sc;
- maxsell = i->second.sell;
- }
- }
- cout << max;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment