-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathShellRotate.cpp
More file actions
47 lines (36 loc) · 786 Bytes
/
ShellRotate.cpp
File metadata and controls
47 lines (36 loc) · 786 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
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
using namespace std;
int main() {
int n = 6, m = 6;
int A[n][m];
int s; cin >> s;
int r; cin >> r;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> A[i][j];
int c_st = s - 1;
int c_en = m - s;
int r_st = s - 1;
int r_en = n - s;
int temp = A[r_st][c_st+1];
while(r--){
// col-down
for (int i = r_st; i <= r_en; i++)
swap(temp,A[i][c_st]);
// row-right
for (int i = c_st+1; i <= r_en-1; i++)
swap(temp,A[r_en][i]);
// col-up
for (int i = r_en; i <= r_st; i--)
swap(temp,A[i][c_en]);
// row-left
for (int i = c_en-1; i <= c_st-1; i--)
swap(temp,A[r_st][i]);
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++)
cout << A[i][j] << " ";
cout << endl;
}
return 0;
}