StoneHaos

testsimon

Oct 26th, 2020
763
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     int n;
  9.     cin >> n;
  10.     vector<int> v(n);
  11.     for (int i = 0; i < n; ++ i)
  12.         cin >> v[i];
  13.     int beg = 0;
  14.     for (int i = 0; i < n - 1; ++ i) {
  15.         if (v[i] < v[i + 1]) {
  16.             beg = i;
  17.             while (i != n - 1 && v[i] < v[i + 1])
  18.                 ++ i;
  19.             reverse(v.begin() + beg, v.begin() + i + 1);
  20.         }
  21.     }
  22.     for (int i = 0; i < n; ++ i) {
  23.         cout << v[i] << " ";
  24.     }
  25.     cout << "\n";
  26.     return 0;
  27. }
  28.  
  29. // 1 2 3 0 1 2 3 2 1 0 1 2 3 4
RAW Paste Data