Advertisement
Korotkodul

1H

Sep 28th, 2023 (edited)
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <cmath>
  2. #include <ctime>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::max;
  9. using std::min;
  10. using std::string;
  11. using std::vector;
  12.  
  13. vector<int> F(vector<int> aa) {
  14.   int nn = aa.size();
  15.   if (nn <= 1) {
  16.     return aa;
  17.   }
  18.   int pivid = rand() % nn;
  19.   int piv = aa[pivid];
  20.   vector<int> bb;
  21.   vector<int> cc;
  22.   for (int ii = 0; ii < nn; ++ii) {
  23.     if (aa[ii] >= piv) {
  24.       cc.push_back(aa[ii]);
  25.     } else {
  26.       bb.push_back(aa[ii]);
  27.     }
  28.   }
  29.   bb = F(bb);
  30.   cc = F(cc);
  31.   vector<int> dd;
  32.   for (int ii : bb) {
  33.     dd.push_back(ii);
  34.   }
  35.   for (int ii : cc) {
  36.     dd.push_back(ii);
  37.   }
  38.   return dd;
  39. }
  40.  
  41. int main() {
  42.   /*std::ios::sync_with_stdio(false);
  43.   std::cin.tie(0);
  44.   std::cout.tie(0);*/
  45.   int nn;
  46.   cin >> nn;
  47.   vector<int> aa(nn);
  48.   for (int& ii : aa) {
  49.     cin >> ii;
  50.   }
  51.   aa = F(aa);
  52.   for (int ii : aa) {
  53.     cout << ii << ' ';
  54.   }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement