Advertisement
jbn6972

Untitled

Sep 9th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. // Code Written by : John Nixon
  2. // Date: 09:09:2022  Time: 19:07:58
  3. // Copyrights are applicable
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. #define ll long long
  7. #define vi vector<int>
  8. #define vll vector<long long int>
  9. int main()
  10. {
  11. #ifndef ONLINE_JUDGE
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14. #endif
  15.     std::ios::sync_with_stdio(false);
  16.     int n, num;
  17.     cin >> n;
  18.     vi arr;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         cin >> num;
  22.         arr.push_back(num);
  23.     }
  24.  
  25.     int curr, tmp;
  26.     for (int i = 0; i < n ; i += 2 )
  27.     {
  28.         curr = arr[n - 1];
  29.         for (int j = n - 2; j >= i; j--)
  30.         {
  31.             arr[j + 1] = arr[j];
  32.         }
  33.         arr[i] = curr;
  34.     }
  35.  
  36.     for (auto num : arr)
  37.     {
  38.         cout << num << " ";
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement