Skip to content

Commit b8d1dee

Browse files
authored
Create 17 BOJ G3 봄버맨 2.md
1 parent 973487b commit b8d1dee

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception{
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
StringBuilder sb = new StringBuilder();
10+
11+
int R = Integer.parseInt(st.nextToken());
12+
int C = Integer.parseInt(st.nextToken());
13+
int N = Integer.parseInt(st.nextToken());
14+
int[][] board = new int[R][C];
15+
int[][] dir = new int[][] {{1,0},{-1,0},{0,1},{0,-1}};
16+
17+
for (int i = 0; i < R; i++) {
18+
String line = br.readLine();
19+
for (int j = 0; j < C; j++) {
20+
if (line.charAt(j) == '.') continue;
21+
board[i][j] = 2;
22+
}
23+
}
24+
int time = 1;
25+
if(N > 5) N = (N % 4) + 4;
26+
while (time < N) {
27+
if (time % 2 == 1) { //폭탄 설치
28+
for (int i = 0; i < R; i++) {
29+
for (int j = 0; j < C; j++) {
30+
if (board[i][j] == 0) board[i][j] = 3;
31+
else board[i][j]--;
32+
}
33+
}
34+
} else { //폭탄시간 감소
35+
for (int i = 0; i < R; i++) {
36+
for (int j = 0; j < C; j++) {
37+
if (board[i][j] == 1) {
38+
board[i][j]--;
39+
for (int[] d : dir) {
40+
int ny = i + d[0];
41+
int nx = j + d[1];
42+
if (ny < 0 || ny >= R || nx < 0 || nx >= C) continue;
43+
if(board[ny][nx] == 1) continue;
44+
board[ny][nx] = 0;
45+
}
46+
} else if (board[i][j] > 1) board[i][j]--;
47+
}
48+
}
49+
}
50+
time++;
51+
}
52+
for (int i = 0; i < R; i++) {
53+
for (int j = 0; j < C; j++) {
54+
if (board[i][j] > 0) sb.append('O');
55+
else sb.append('.');
56+
}
57+
sb.append("\n");
58+
}
59+
System.out.println(sb);
60+
}
61+
}
62+
63+
```

0 commit comments

Comments
 (0)