artemgf

Порядок

Apr 15th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 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. long long n, k[500001], prom, prom2, maxan;
  16.  
  17. int main()
  18. {
  19.     long long max;
  20.     max = 0;
  21.     cin >> n;
  22.     for (int i = 1; i <= n; i++)
  23.         cin >> k[i];
  24.  
  25.     sort(k + 1, k + n + 1);
  26.  
  27.     prom = k[1];
  28.     prom2 = 1;
  29.     maxan = prom;
  30.     for (int i = 2; i <= n; i++)
  31.         if (k[i] != prom)
  32.         {
  33.             if (prom2 > max)
  34.             {
  35.                 maxan = prom;
  36.                 max = prom2;
  37.             }
  38.             prom = k[i];
  39.             prom2 = 1;
  40.         }
  41.         else
  42.             prom2++;
  43.  
  44.     if (prom2 > max)
  45.     {
  46.         maxan = prom;
  47.         max = prom2;
  48.     }
  49.  
  50.     cout << maxan;
  51.     _getch();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment