artemgf

Девайсы

Apr 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8. #include <string>
  9. #include <math.h>
  10. #include <vector>
  11. #include <cmath>
  12.  
  13. using namespace std;
  14.  
  15. struct dev
  16. {
  17.     long long sell;
  18.     long long sc;
  19. };
  20.  
  21. bool operator< (dev p1, dev p2)
  22. {
  23.     if (p1.sc == p2.sc)
  24.         return p1.sell < p2.sc;
  25.     else
  26.         return p1.sc < p2.sc;
  27. }
  28. int main()
  29. {
  30.     string s, max;
  31.     map <string, dev> product;
  32.     long long maxsc=-1, maxsell=-1;
  33.  
  34.     while (cin >> s)
  35.     {
  36.         string prom;
  37.         int prom2;
  38.         cin >> prom;
  39.         cin >> prom2;
  40.         if (product.find(prom) != product.end())
  41.         {
  42.             if (product[prom].sell > prom2)
  43.                 product[prom].sell = prom2;
  44.             product[prom].sc++;
  45.         }
  46.         else
  47.         {
  48.             dev prom3;
  49.             prom3.sell = prom2;
  50.             prom3.sc = 1;
  51.             product.insert(pair <string, dev>(prom, prom3));
  52.         }
  53.     }
  54.  
  55.     for (auto i = product.begin(); i != product.end(); i++)
  56.     {
  57.         if (i->second.sc > maxsc)
  58.         {
  59.             max = i->first;
  60.             maxsc = i->second.sc;
  61.             maxsell = i->second.sell;
  62.         }
  63.         else
  64.             if (i->second.sc == maxsc)
  65.                 if (i->second.sell < maxsell)
  66.                 {
  67.                     max = i->first;
  68.                     maxsc = i->second.sc;
  69.                     maxsell = i->second.sell;
  70.                 }
  71.     }
  72.  
  73.     cout << max;
  74.  
  75.     _getch();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment