- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14499.java
More file actions
Latest commit
122 lines (92 loc) · 1.76 KB
/
Copy path14499.java
File metadata and controls
122 lines (92 loc) · 1.76 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
importjava.util.*;
publicclassMain {
staticclassDice {
intx,y;
intfront, rear, left, right, up, down;
Dice(intx, inty) {this.x=x; this.y=y;
front = rear = left = right = up = down = 0;}
}
staticint[][] map;
staticDiced;
publicstaticvoidmain(String[] arg) {
Scannersc = newScanner(System.in);
intn = sc.nextInt();
intm = sc.nextInt();
intx = sc.nextInt();
inty = sc.nextInt();
intk = sc.nextInt();
map = newint[n][m];
for(inti=0; i<n; i++) {
for(intj=0; j<m; j++) {
map[i][j] = sc.nextInt();
}
}
int[] move = newint[k];
for(inti=0; i<k; i++) {
move[i] = sc.nextInt();
}
d = newDice(x, y);
for(intnum : move) {
if(num == 1 && d.y+1 < m) {
right();
System.out.println(d.up);
}
elseif(num == 2 && d.y-1 >= 0) {
left();
System.out.println(d.up);
}
elseif(num == 3 && d.x-1 >= 0) {
up();
System.out.println(d.up);
}
elseif(num == 4 && d.x+1 < n) {
down();
System.out.println(d.up);
}
}
}
staticvoidcheck() {
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;
}
}
staticvoidright() {
inttemp = d.down;
d.down = d.right;
d.right = d.up;
d.up = d.left;
d.left = temp;
d.y++;
check();
}
staticvoidleft() {
inttemp = d.down;
d.down = d.left;
d.left = d.up;
d.up = d.right;
d.right= temp;
d.y--;
check();
}
staticvoidup() {
inttemp = d.up;
d.up = d.front;
d.front = d.down;
d.down = d.rear;
d.rear = temp;
d.x--;
check();
}
staticvoiddown() {
inttemp = d.down;
d.down = d.front;
d.front = d.up;
d.up = d.rear;
d.rear = temp;
d.x++;
check();
}
}