Skip to content

Commit e9a9fd1

Browse files
authored
Merge pull request #1252 from AlgorithmWithGod/lkhyun
[20251028] BOJ / G4 / 주사위 굴리기 / 이강현
2 parents 0e3e187 + fdd4467 commit e9a9fd1

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static class State{
7+
int x,y;
8+
int[] row = new int[3];
9+
int[] col = new int[3];
10+
State(int x, int y){
11+
this.x = x;
12+
this.y = y;
13+
}
14+
public void rolling(int direction, int[][] map) throws Exception{
15+
if(direction == 1){ //동쪽
16+
if(y == map[0].length-1) return;
17+
int temp = col[2];
18+
col[2] = row[2];
19+
row[2] = row[1];
20+
row[1] = row[0];
21+
row[0] = temp;
22+
y++;
23+
check();
24+
return;
25+
}
26+
if(direction == 2){ //서쪽
27+
if(y == 0) return;
28+
int temp = col[2];
29+
col[2] = row[0];
30+
row[0] = row[1];
31+
row[1] = row[2];
32+
row[2] = temp;
33+
y--;
34+
check();
35+
return;
36+
}
37+
if(direction == 3){ //북쪽
38+
if(x == 0) return;
39+
int temp = col[2];
40+
col[2] = col[0];
41+
col[0] = row[1];
42+
row[1] = col[1];
43+
col[1] = temp;
44+
x--;
45+
check();
46+
return;
47+
}
48+
if(direction == 4){ //남쪽
49+
if(x == map.length-1) return;
50+
int temp = col[2];
51+
col[2] = col[1];
52+
col[1] = row[1];
53+
row[1] = col[0];
54+
col[0] = temp;
55+
x++;
56+
check();
57+
return;
58+
}
59+
}
60+
public void check() throws Exception{
61+
if(map[x][y] == 0){
62+
map[x][y] = col[2];
63+
}else{
64+
col[2] = map[x][y];
65+
map[x][y] = 0;
66+
}
67+
bw.write(row[1]+"\n");
68+
}
69+
}
70+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
71+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
72+
static StringBuilder sb = new StringBuilder();
73+
static StringTokenizer st;
74+
static int N,M,X,Y,K;
75+
static int[][] map;
76+
public static void main(String[] args) throws Exception {
77+
st = new StringTokenizer(br.readLine());
78+
N = Integer.parseInt(st.nextToken());
79+
M = Integer.parseInt(st.nextToken());
80+
X = Integer.parseInt(st.nextToken());
81+
Y = Integer.parseInt(st.nextToken());
82+
K = Integer.parseInt(st.nextToken());
83+
84+
map = new int[N][M];
85+
for(int i = 0; i<N; i++){
86+
st = new StringTokenizer(br.readLine());
87+
for(int j = 0; j<M; j++){
88+
map[i][j] = Integer.parseInt(st.nextToken());
89+
}
90+
}
91+
State dice = new State(X,Y);
92+
93+
st = new StringTokenizer(br.readLine());
94+
for(int i = 0; i<K; i++){
95+
int cmd = Integer.parseInt(st.nextToken());
96+
dice.rolling(cmd, map);
97+
}
98+
bw.close();
99+
}
100+
}
101+
```

0 commit comments

Comments
 (0)