Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main ()
- {
- int x = 0;
- int count = 0;
- int max = 0; // Кол-во повторений наиболее частого числа
- int maxIndex = 0; // Наиболее частое число
- cin >> x;
- int *a = new int [x];
- for (int i = 0; i < x; ++i) // Ввожу массив с клавиатуры
- {
- cin >> a[i];
- }
- for (int i = 0; i<x; ++i){ /* Проверяю каждое число массива на совпадения
- с остальными числами массива
- */
- count = 0;
- if ((x - i) < max)
- {
- break;
- }
- for (int j = 0;j < x; ++j){
- if (a[i] == a[j]){
- ++count;
- }
- }
- if (count > max)
- {
- max = count;
- maxIndex = a[i];
- }
- }
- delete []a;
- cout << "max count index: " << maxIndex << " Max index: "<< max << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement