-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14499.java
122 lines (92 loc) · 1.76 KB
/
14499.java
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
import java.util.*;
public class Main {
static class Dice {
int x,y;
int front, rear, left, right, up, down;
Dice(int x, int y) {this.x=x; this.y=y;
front = rear = left = right = up = down = 0;}
}
static int[][] map;
static Dice d;
public static void main(String[] arg) {
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();
map = new int[n][m];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
map[i][j] = sc.nextInt();
}
}
int[] move = new int[k];
for(int i=0; i<k; i++) {
move[i] = sc.nextInt();
}
d = new Dice(x, y);
for(int num : move) {
if(num == 1 && d.y+1 < m) {
right();
System.out.println(d.up);
}
else if(num == 2 && d.y-1 >= 0) {
left();
System.out.println(d.up);
}
else if(num == 3 && d.x-1 >= 0) {
up();
System.out.println(d.up);
}
else if(num == 4 && d.x+1 < n) {
down();
System.out.println(d.up);
}
}
}
static void check() {
if(map[d.x][d.y] == 0) {
map[d.x][d.y] = d.down;
} else {
d.down = map[d.x][d.y];
map[d.x][d.y] = 0;
}
}
static void right() {
int temp = d.down;
d.down = d.right;
d.right = d.up;
d.up = d.left;
d.left = temp;
d.y++;
check();
}
static void left() {
int temp = d.down;
d.down = d.left;
d.left = d.up;
d.up = d.right;
d.right= temp;
d.y--;
check();
}
static void up() {
int temp = d.up;
d.up = d.front;
d.front = d.down;
d.down = d.rear;
d.rear = temp;
d.x--;
check();
}
static void down() {
int temp = d.down;
d.down = d.front;
d.front = d.up;
d.up = d.rear;
d.rear = temp;
d.x++;
check();
}
}