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
import java.util.Scanner;
import java.io.FileInputStream;
 
class Main {
    public static void main(String args[]) throws Exception {
        // Scanner sc = new Scanner(new FileInputStream("sample_input.txt"));
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int k = sc.nextInt();
 
        int map[][] = new int[n][m];
        int dice[] = { 000000 };
 
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                map[i][j] = sc.nextInt();
            }
        }
 
        for (int i = 0; i < k; i++) {
            int move = sc.nextInt();
 
            switch (move) {
            case 1:
                if (y + 1 < m) {
                    y = y + 1;
 
                    int temp = dice[1];
                    dice[1= dice[5];
                    dice[5= dice[3];
                    dice[3= dice[2];
                    dice[2= temp;
 
                    check_map(map, x, y, dice);
                }
                break;
            case 2:
                if (0 <= y - 1) {
                    y = y - 1;
 
                    int temp = dice[1];
                    dice[1= dice[2];
                    dice[2= dice[3];
                    dice[3= dice[5];
                    dice[5= temp;
 
                    check_map(map, x, y, dice);
                }
                break;
            case 3:
                if (0 <= x - 1) {
                    x = x - 1;
 
                    int temp = dice[0];
                    dice[0= dice[5];
                    dice[5= dice[4];
                    dice[4= dice[2];
                    dice[2= temp;
 
                    check_map(map, x, y, dice);
                }
                break;
            case 4:
                if (x + 1 < n) {
                    x = x + 1;
 
                    int temp = dice[0];
                    dice[0= dice[2];
                    dice[2= dice[4];
                    dice[4= dice[5];
                    dice[5= temp;
 
                    check_map(map, x, y, dice);
                }
                break;
            default:
                break;
            } // switch
 
        } // for
 
    } // main
 
    static void check_map(int[][] map, int x, int y, int[] dice) {
        if (map[x][y] == 0)
            map[x][y] = dice[5];
        else {
            dice[5= map[x][y];
            map[x][y] = 0;
        }
 
        System.out.println(dice[2]);
    }
}
cs


'공부 > 알고리즘문제' 카테고리의 다른 글

백준 1012 유기농 배추  (0) 2017.04.13
백준 13458 시험 감독  (0) 2017.04.12
코드그라운드 시험 공부  (0) 2017.04.11
코드그라운드 숫자 골라내기  (0) 2017.04.11
코드그라운드 할인권  (0) 2017.04.11