-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.cpp
More file actions
40 lines (32 loc) · 707 Bytes
/
rotate.cpp
File metadata and controls
40 lines (32 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
void Rotate(int arr[], int d, int size) {
/* Don't write main().
* Don't read input, it is passed as function argument.
* No need to print or return the output.
* Taking input and printing the output is handled automatically.
*/
int temp;
while(d--)
{
temp=arr[0];
for(int i=0;i<size-1;i++)
{
arr[i]=arr[i+1];
}
arr[size-1]=temp;
}
}
int main() {
int size;
int d;
cin>>size;
int *input=new int[1+size];
for(int i=0;i<size;i++)
cin>>input[i];
cin >> d;
Rotate(input,d,size);
for(int i=0;i<size;i++)
cout<<input[i]<<" ";
return 0;
}