SHARE
TWEET

Untitled

a guest Oct 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. void insertionSort(int* a, int n) {
  7.     int j;
  8.     for (int i = 0; i < n; ++i) {
  9.         int x = a[i];
  10.         j = i - 1;
  11.         while (j >= 0 && x <= a[j]) {
  12.             a[j + 1] = a[j];
  13.             --j;
  14.         }
  15.         a[j + 1] = x;
  16.     }
  17. }
  18.  
  19. int main() {
  20.     int n;
  21.     cin >> n;
  22.     int* age = new int[n];
  23.     for (int i = 0; i < n; ++i) {
  24.         cin >> age[i];
  25.     }
  26.     sort(age, age + n);
  27.     int maxCounter = 1, mostCommonAge = age[0], tempCounter = 1;
  28.     for (int i = 1; i < n; ++i) {
  29.         while (age[i] == age[i - 1] && i < n) {
  30.             ++tempCounter;
  31.             ++i;
  32.         }
  33.         if (tempCounter > maxCounter) {
  34.             maxCounter = tempCounter;
  35.             mostCommonAge = age[i - 1];
  36.         }
  37.         tempCounter = 1;
  38.     }
  39.     cout << mostCommonAge;
  40.     delete[] age;
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top