-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathimplementation | Matrix layer rotation
More file actions
61 lines (51 loc) · 1.44 KB
/
implementation | Matrix layer rotation
File metadata and controls
61 lines (51 loc) · 1.44 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
57
58
59
60
61
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int rows,cols,rot;
scanf("%d%d%d",&rows,&cols,&rot);
int arr[rows][cols];
int result[rows][cols];
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
scanf("%d", &arr[r][c]);
}
}
rows--;
cols--;
for (int r = 0; r <= rows; r++) {
for (int c = 0; c <= cols; c++) {
int x = r < rows - r ? r : rows - r;
int y = c < cols - c ? c : cols - c;
int min = x < y ? x : y;
int maxRow = rows - min;
int maxCol = cols - min;
int parameter = (maxRow + maxCol) * 2 - min * 4;
int row = r;
int col = c;
for (int a = 0; a < rot%parameter; a++) {
if (col == min && row < maxRow) {
row++;
}
else if (row == maxRow && col < maxCol) {
col++;
}
else if (row > min && col == maxCol) {
row--;
}
else if (row == min && col > min) {
col--;
}
}
result[row][col] = arr[r][c];
}
}
for (int r = 0; r <= rows; r++) {
for (int c = 0; c <= cols; c++) {
printf("%d ", result[r][c]);
}
printf("\n");
}
return 0;
}