Advertisement
cacodemon665

Лаба 4 Вариант 3

Dec 23rd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int k;
  10.  
  11.     cout << "Enter k:" << endl;
  12.     cin >> k;
  13.  
  14.     int arr[100000];
  15.  
  16.     for (int i = 0; i < k; i++)
  17.         cin >> arr[i];
  18.  
  19.     int max_val = 0, max_cnt = 0;
  20.  
  21.     for (int i = 0; i < k; i++)
  22.     {
  23.         int cnt = 0;
  24.  
  25.         for (int j = i; j < k; j++)
  26.             if (arr[i] == arr[j])
  27.                 cnt++;
  28.  
  29.         if (cnt > max_cnt)
  30.         {
  31.             max_cnt = cnt;
  32.             max_val = arr[i];
  33.         }
  34.     }
  35.  
  36.     cout << max_val;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement