-
Notifications
You must be signed in to change notification settings - Fork 0
/
zerojudge_a867.java
78 lines (76 loc) · 1.59 KB
/
zerojudge_a867.java
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
package zerojudgeProject;
import java.util.Scanner;
public class zerojudge {
static char[][] map;
static int height=15,width=30;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String buffer;
map = new char [height][width];
while(scanner.hasNext()){
for(int row =0;row<height;row++) {
buffer=scanner.next();
for(int col =0;col<width;col++) {
map[row][col] = buffer.charAt(col);
}
}
//showMap();
countMine();
showMap();
}
System.out.println("Hello");
}
static void showMap(){
for(int row =0;row<height;row++) {
for(int col =0;col<width;col++) {
System.out.print(map[row][col]);
}
System.out.print("\n");
}
System.out.print("\n");
}
static void countMine(){
int counter=0;
for (int y = 0; y < width ; y++) {
for (int x = 0; x < height; x++) {
if(map[x][y]!='*'){
if(x>0){
if(map[x-1][y] =='*')
counter++;
}
if(x < height-1){
if(map[x+1][y] =='*')
counter++;
}
if(y>0){
if(map[x][y-1] =='*')
counter++;
}
if(y < width-1){
if(map[x][y+1] =='*')
counter++;
}
if(x>0 && y>0){
if(map[x-1][y-1] =='*')
counter++;
}
if(x>0 && y < width-1){
if(map[x-1][y+1] =='*')
counter++;
}
if((x < height-1) && y>0){
if(map[x+1][y-1] =='*')
counter++;
}
if((x < height-1) && y < width-1){
if(map[x+1][y+1] =='*')
counter++;
}
if(counter !=0)
map[x][y] = Integer.toString(counter).charAt(0);
counter = 0;
}
}
}
}
}