Advertisement
Spocoman

07. Array Rotation

Nov 18th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int length, step;
  7.     cin >> length;
  8.  
  9.     int* arr = new int[length];
  10.  
  11.     for (int i = 0; i < length; i++) {
  12.         cin >> arr[i];
  13.     }
  14.  
  15.     cin >> step;
  16.  
  17.     for (int i = 0; i < length; i++) {
  18.         cout << arr[((step + i) % length)] << ' ';
  19.     }
  20.  
  21.     cout << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement