-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackerRankBomberman.java
More file actions
88 lines (78 loc) · 2.54 KB
/
hackerRankBomberman.java
File metadata and controls
88 lines (78 loc) · 2.54 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
package javaBackjoon;
import java.util.Scanner;
public class hackerRankBomberman {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int row, col, time;
row = input.nextInt();
col = input.nextInt();
time = input.nextInt();
if(time == 1) {
for(int i = 0; i < row; i++)
System.out.println(input.next());
return;
}
int[][] map = new int[row + 2][col + 2];
for(int i = 1; i <= row; i++) {
String s = input.next();
for(int j = 1; j <= col; j++) {
if(s.charAt(j - 1) == '.') map[i][j] = 0;
else map[i][j] = 1;
}
}
if ((time%2) == 0){
for(int i = 0; i < row; i++) {
for(int j = 0; j < col; j++)
System.out.print("O");
System.out.println();
}
return;
}
int[][] plantedMap = new int[row + 2][col + 2];
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++) {
if(map[i][j] == 1) {
plantedMap[i][j] = 1;
plantedMap[i-1][j] = 1;
plantedMap[i+1][j] = 1;
plantedMap[i][j-1] = 1;
plantedMap[i][j+1] = 1;
}
}
}
int[][] plantedMap2 = new int[row + 2][col + 2];
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++) {
if(plantedMap[i][j] == 0) {
plantedMap2[i][j] = 1;
plantedMap2[i-1][j] = 1;
plantedMap2[i+1][j] = 1;
plantedMap2[i][j-1] = 1;
plantedMap2[i][j+1] = 1;
}
}
}
if ((time - 3) % 4 == 0) {
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++) {
if(plantedMap[i][j] == 1)
System.out.print('.');
else
System.out.print('O');
}
System.out.println();
}
}
else if ((time - 1) % 4 == 0) {
for(int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++) {
if(plantedMap2[i][j] == 0)
System.out.print('O');
else
System.out.print('.');
}
System.out.println();
}
}
}
}