forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14499.cpp
More file actions
131 lines (115 loc) · 2.48 KB
/
Copy path14499.cpp
File metadata and controls
131 lines (115 loc) · 2.48 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
using namespace std;
int dice[6] = { 0, 0, 0, 0, 0, 0 };
int diceX, diceY;
int N, M, K;
int** board;
int* command;
void dice_w() {
int tmp[6];
for (int i = 0; i < 6; i++) tmp[i] = dice[i];
dice[1] = tmp[0];
dice[5] = tmp[1];
dice[3] = tmp[5];
dice[0] = tmp[3];
}
void dice_e() {
int tmp[6];
for (int i = 0; i < 6; i++) tmp[i] = dice[i];
dice[5] = tmp[3];
dice[3] = tmp[0];
dice[0] = tmp[1];
dice[1] = tmp[5];
}
void dice_n() {
int tmp[6];
for (int i = 0; i < 6; i++) tmp[i] = dice[i];
dice[4] = tmp[0];
dice[0] = tmp[2];
dice[2] = tmp[5];
dice[5] = tmp[4];
}
void dice_s() {
int tmp[6];
for (int i = 0; i < 6; i++) tmp[i] = dice[i];
dice[0] = tmp[4];
dice[2] = tmp[0];
dice[4] = tmp[5];
dice[5] = tmp[2];
}
int main()
{
cin >> N >> M >> diceX >> diceY >> K;
board = new int* [N];
for (int i = 0; i < N; i++) {
board[i] = new int[M];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> board[i][j];
}
}
command = new int[K];
for (int i = 0; i < K; i++) {
cin >> command[i];
}
for (int i = 0; i < K; i++) {
switch (command[i]) {
case 1:
//east
diceY++;
break;
case 2:
//west
diceY--;
break;
case 3:
//north
diceX--;
break;
case 4:
//south
diceX++;
break;
}
if (diceX < 0 || diceX >= N || diceY < 0 || diceY >= M) {
switch (command[i]) {
case 1:
diceY--;
break;
case 2:
diceY++;
break;
case 3:
diceX++;
break;
case 4:
diceX--;
break;
}
continue;
}
switch (command[i]) {
case 1:
dice_e();
break;
case 2:
dice_w();
break;
case 3:
dice_n();
break;
case 4:
dice_s();
break;
}
if (board[diceX][diceY] == 0) {
board[diceX][diceY] = dice[5];
}
else {
dice[5] = board[diceX][diceY];
board[diceX][diceY] = 0;
}
cout << dice[0] << "\n";
}
}