Advertisement
MathQ_

Untitled

May 12th, 2023
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     vector<int> a = {8, 5, 10, 6, 10, 7, 8, 11};
  9.     sort(a.begin(), a.end(), [](int i, int j){
  10.         if (i % 2 == j % 2) {
  11.             return i < j;
  12.         } else {
  13.             return i % 2 > j % 2;
  14.         }
  15.     });
  16.     for (auto element : a) {
  17.         cout << element << " ";
  18.     }
  19.     cout << '\n';
  20.  
  21.     int cur_cnt = 0;
  22.     vector<int> ans;
  23.     for (int i = 0; i < a.size(); ++i) {
  24.         int j = i;
  25.         while (j < a.size() - 1 and a[j + 1] == a[j]) {
  26.             ++j;
  27.         }
  28.         if (j - i + 1 > cur_cnt) {
  29.             cur_cnt = j - i + 1;
  30.             ans.clear();
  31.             ans = {a[j]};
  32.         } else if (j - i + 1 == cur_cnt) {
  33.             ans.push_back(a[j]);
  34.         }
  35.     }
  36.     for (auto element : ans) {
  37.         cout << element << " ";
  38.     }
  39.     cout << '\n';
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement