#include
#include
using namespace std;
const int MAX = 20;
int n, m, x, y, k;
int num[MAX][MAX];
int dice[6],copynum[6];
void checkzero() {
if (num[x][y] != 0) {
dice[5] = num[x][y];
num[x][y] = 0;
}
else {
num[x][y] = dice[5];
}
}
bool checkend() {
if (x < 0 || x >= n || y < 0 || y >= m)
return false;
else
return true;
}
int main(void) {
cin >> n >> m >> x >> y >> k;
memset(dice, 0, sizeof(dice));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> num[i][j];
}
}
for (int i = 0; i < k; i++) {
int cmd;
cin >> cmd;
for (int j = 0; j < 6; j++) {
copynum[j] = dice[j];
}
if (cmd == 1) {
y += 1;
if (!checkend()) {
y -= 1;
continue;
}
dice[3] = copynum[2];
dice[2] = copynum[1];
dice[5] = copynum[3];
dice[1] = copynum[5];
checkzero();
}
if (cmd == 2) {
y -= 1;
if (!checkend()) {
y += 1;
continue;
}
dice[2] = copynum[3];
dice[1] = copynum[2];
dice[3] = copynum[5];
dice[5] = copynum[1];
checkzero();
}
if (cmd == 3) {
x -= 1;
if (!checkend()) {
x += 1;
continue;
}
dice[0] = copynum[2];
dice[2] = copynum[4];
dice[4] = copynum[5];
dice[5] = copynum[0];
checkzero();
}
if (cmd == 4) {
x += 1;
if (!checkend()) {
x -= 1;
continue;
}
dice[2] = copynum[0];
dice[4] = copynum[2];
dice[5] = copynum[4];
dice[0] = copynum[5];
checkzero();
}
cout << dice[2] << endl;
}
return 0;
}
'백준 알고리즘 > 시뮬레이션' 카테고리의 다른 글
백준 14503번 C++ (0) | 2019.08.28 |
---|---|
백준 2455번 C++ (0) | 2019.08.26 |
백준 3190 C++ (0) | 2019.04.07 |
백준 3190번 C++ (0) | 2019.01.29 |
백준 14499번 C++ (0) | 2019.01.27 |