Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- void insertionSort(int* a, int n) {
- int j;
- for (int i = 0; i < n; ++i) {
- int x = a[i];
- j = i - 1;
- while (j >= 0 && x <= a[j]) {
- a[j + 1] = a[j];
- --j;
- }
- a[j + 1] = x;
- }
- }
- int main() {
- int n;
- cin >> n;
- int* age = new int[n];
- for (int i = 0; i < n; ++i) {
- cin >> age[i];
- }
- sort(age, age + n);
- int maxCounter = 1, mostCommonAge = age[0], tempCounter = 1;
- for (int i = 1; i < n; ++i) {
- while (age[i] == age[i - 1] && i < n) {
- ++tempCounter;
- ++i;
- }
- if (tempCounter > maxCounter) {
- maxCounter = tempCounter;
- mostCommonAge = age[i - 1];
- }
- tempCounter = 1;
- }
- cout << mostCommonAge;
- delete[] age;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement