-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.cpp
More file actions
75 lines (59 loc) · 1.43 KB
/
test2.cpp
File metadata and controls
75 lines (59 loc) · 1.43 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
using namespace std;
int map[5][5] = { {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}};
// 90도 회전
void rotate90(int x, int y, int len) {
int copy_map[len+1][len+1];
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
copy_map[j][len-i-1] = map[x+i][y+j];
}
}
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
map[x+i][y+j] = copy_map[i][j];
}
}
}
// 180도 회전
void rotate180(int x, int y, int len) {
int copy_map[len+1][len+1];
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
copy_map[len-i-1][len-j-1] = map[x+i][y+j];
}
}
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
map[x+i][y+j] = copy_map[i][j];
}
}
}
// 270도 회전
void rotate270(int x, int y, int len) {
int copy_map[len+1][len+1];
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
copy_map[len-j-1][i] = map[x+i][y+j];
}
}
for(int i=0; i<len; i++) {
for(int j=0; j<len; j++) {
map[x+i][y+j] = copy_map[i][j];
}
}
}
void print_map() {
for(int i=0; i<5; i++) {
for(int j=0; j<5; j++) {
cout << map[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
}
int main() {
print_map();
rotate270(1, 1, 3);
print_map();
}