Skip to content

Commit 0e8feab

Browse files
committed
[Simulation] baekjoon-14499
1 parent 365741e commit 0e8feab

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

โ€ŽREADME.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
| 07 | | [Baekjoon-2563 ์ƒ‰์ข…์ด](./src/Simulation/P2563) | |
3737
| 08 | | [Baekjoon-16927 ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 2](./src/Simulation/P16927) | |
3838
| 09 | | [Baekjoon-16935 ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 3](./src/Simulation/P16935) | |
39+
| 10 | | [Baekjoon-14499 ์ฃผ์‚ฌ์œ„ ๊ตด๋ฆฌ๊ธฐ](./src/Simulation/P14499) | ์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ |
3940

4041
## String
4142

โ€Žsrc/Simulation/P14499/Main.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package Simulation.P14499;
2+
3+
import java.io.*;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
8+
static int N, M, i, j, K;
9+
static int[][] map;
10+
static int[] dice = new int[7];
11+
12+
static int[] di = {0, 0, -1, 1};
13+
static int[] dj = {1, -1, 0, 0};
14+
15+
public static void main(String[] args) throws Exception {
16+
System.setIn(new FileInputStream("src/Simulation/P14499/input.txt"));
17+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
18+
StringTokenizer st = new StringTokenizer(br.readLine());
19+
20+
N = stoi(st.nextToken());
21+
M = stoi(st.nextToken());
22+
i = stoi(st.nextToken());
23+
j = stoi(st.nextToken());
24+
K = stoi(st.nextToken());
25+
26+
map = new int[N][M];
27+
for (int i = 0; i < N; i++) {
28+
st = new StringTokenizer(br.readLine());
29+
for (int j = 0; j < M; j++) {
30+
map[i][j] = stoi(st.nextToken());
31+
}
32+
}
33+
34+
st = new StringTokenizer(br.readLine());
35+
while (K-- > 0) {
36+
int cmd = stoi(st.nextToken());
37+
38+
int to_i = i + di[cmd-1], to_j = j + dj[cmd-1];
39+
if (!isValidPath(to_i, to_j)) continue;
40+
i = to_i; j = to_j;
41+
42+
switch (cmd) {
43+
case 1:
44+
int tmp = dice[4];
45+
dice[4] = dice[6];
46+
dice[6] = dice[3];
47+
dice[3] = dice[1];
48+
dice[1] = tmp;
49+
break;
50+
case 2:
51+
tmp = dice[3];
52+
dice[3] = dice[6];
53+
dice[6] = dice[4];
54+
dice[4] = dice[1];
55+
dice[1] = tmp;
56+
break;
57+
case 3:
58+
tmp = dice[5];
59+
dice[5] = dice[6];
60+
dice[6] = dice[2];
61+
dice[2] = dice[1];
62+
dice[1] = tmp;
63+
break;
64+
case 4:
65+
tmp = dice[2];
66+
dice[2] = dice[6];
67+
dice[6] = dice[5];
68+
dice[5] = dice[1];
69+
dice[1] = tmp;
70+
break;
71+
}
72+
73+
if (map[i][j] == 0) map[i][j] = dice[6];
74+
else { dice[6] = map[i][j]; map[i][j] = 0; }
75+
76+
System.out.println(dice[1]);
77+
}
78+
}
79+
80+
static boolean isValidPath(int i, int j) {
81+
return 0 <= i && i < N && 0 <= j && j < M;
82+
}
83+
84+
static int stoi(String s) { return Integer.parseInt(s); }
85+
}

โ€Žsrc/Simulation/P14499/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## [baekjoon-14499] ์ฃผ์‚ฌ์œ„ ๊ตด๋ฆฌ๊ธฐ
2+
3+
![image](https://user-images.githubusercontent.com/22045163/107928146-5032b500-6fbb-11eb-90bf-d7dbcc5ff331.png)
4+
5+
### ํ’€์ด ๊ณผ์ •
6+
7+
์ฒ˜์Œ์— ๋„ˆ๋ฌด ์–ด๋ ต๊ฒŒ ์ƒ๊ฐํ–ˆ์—ˆ๋Š”๋ฐ, ๊ทธ๋ƒฅ ์ˆซ์ž๋Œ€๋กœ ์ฃผ์‚ฌ์œ„๋ฅผ ๋Œ๋ฆฌ๋ฉด ๋œ๋‹ค.
8+
9+
![image](https://user-images.githubusercontent.com/22045163/107930949-02b84700-6fbf-11eb-9b52-18ca66657206.png)
10+
11+
![image](https://user-images.githubusercontent.com/22045163/107928186-5cb70d80-6fbb-11eb-85d7-3109d27f0906.png)

โ€Žsrc/Simulation/P14499/input.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3 3 0 0 16
2+
0 1 2
3+
3 4 5
4+
6 7 8
5+
4 4 1 1 3 3 2 2 4 4 1 1 3 3 2 2

0 commit comments

Comments
ย (0)