티스토리 뷰

구현


- 조건들을 놓치면 시간 끌리는 문제...

- 주사위가 움직이면 면이 어떻게 변하는지 파악하는게 중요!!!



소스 코드


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
#include <iostream>
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define endl '\n'
#define sws ios::sync_with_stdio(false), cin.tie(NULL)
using namespace std;
int dice[4][3];
int map[21][21];
int main() {
    sws;
    int N, M, x, y, K, cmd;
    cin >> N >> M >> x >> y >> K;
    FOR(i, 0, N) FOR(j, 0, M) cin >> map[i][j];
    while (K--) {
        cin >> cmd;
        if (cmd == 1) { //오른쪽
            if (y + 1 == M) continue;
            y++;
            int tmp = dice[3][1];
            dice[3][1= dice[1][2];
            dice[1][2= dice[1][1];
            dice[1][1= dice[1][0];
            dice[1][0= tmp;
            if(map[x][y] != 0) dice[3][1= map[x][y], map[x][y] = 0;
            else map[x][y] = dice[3][1];
            cout << dice[1][1<< endl;
        }
        else if (cmd == 2) { //왼쪽
            if (y == 0continue;
            y--;
            int tmp = dice[3][1];
            dice[3][1= dice[1][0];
            dice[1][0= dice[1][1];
            dice[1][1= dice[1][2];
            dice[1][2= tmp;
            if(map[x][y] != 0) dice[3][1= map[x][y], map[x][y] = 0;
            else map[x][y] = dice[3][1];
            cout << dice[1][1<< endl;
        }
        else if (cmd == 3) { //위쪽
            if (x == 0continue;
            x--;
            int tmp = dice[0][1];
            dice[0][1= dice[1][1];
            dice[1][1= dice[2][1];
            dice[2][1= dice[3][1];
            dice[3][1= tmp;
            if(map[x][y] != 0) dice[3][1= map[x][y], map[x][y] = 0;
            else map[x][y] = dice[3][1];
            cout << dice[1][1<< endl;
        }
        else {
            if (x + 1 == N) continue;
            x++;
            int tmp = dice[3][1];
            dice[3][1= dice[2][1];
            dice[2][1= dice[1][1];
            dice[1][1= dice[0][1];
            dice[0][1= tmp;
            if (map[x][y] != 0) dice[3][1= map[x][y], map[x][y] = 0;
            else map[x][y] = dice[3][1];
            cout << dice[1][1<< endl;
        }
    }
 
}
cs

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/09   »
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
글 보관함