-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.cpp
More file actions
56 lines (47 loc) · 1.33 KB
/
day3.cpp
File metadata and controls
56 lines (47 loc) · 1.33 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int T;
cin >> T;
while (T--) {
int direction, noofrotation, N;
cin >> direction >> noofrotation >> N;
int arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
noofrotation %= N;
if (direction == 0) {
int temp[noofrotation];
for (int i = 0; i < noofrotation; i++) {
temp[i] = arr[i];
}
for (int i = noofrotation; i < N; i++) {
arr[i - noofrotation] = arr[i];
}
for (int i = 0; i < noofrotation; i++) {
arr[N - noofrotation + i] = temp[i];
}
} else if (direction == 1) {
int temp[noofrotation];
for (int i = 0; i < noofrotation; i++) {
temp[i] = arr[N - noofrotation + i];
}
for (int i = N - noofrotation - 1; i >= 0; i--) {
arr[i + noofrotation] = arr[i];
}
for (int i = 0; i < noofrotation; i++) {
arr[i] = temp[i];
}
}
for (int i = 0; i < N; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
return 0;
}