-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP176.java
More file actions
54 lines (43 loc) · 1.29 KB
/
P176.java
File metadata and controls
54 lines (43 loc) · 1.29 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
package p100_199;
import java.util.Scanner;
//accepted
public class P176 {
static char[][] matriz;
public static boolean contarMinas(int i, int j){
int minas = 0;
for (int k=Math.max(0, i-1); k < Math.min(matriz.length, i+2); k++) {
for (int m=Math.max(0, j-1); m < Math.min(matriz[k].length, j+2); m++) {
if (matriz[k][m] == '*') {
minas++;
}
}
}
return minas>5;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b;
a=sc.nextInt();
b=sc.nextInt();
while (a!=0 && b!=0){
int contador = 0;
matriz = new char[b][a];
for (int i=0; i < b; i++) {
String lineaEntrada = sc.next();
for (int j=0; j < a; j++) {
matriz[i][j] = lineaEntrada.charAt(j);
}
}
for(int i=0;i<b;i++){
for(int j=0;j<a;j++){
if (matriz[i][j]=='-' && contarMinas(i,j)){
contador++;
}
}
}
System.out.println(contador);
a=sc.nextInt();
b=sc.nextInt();
}
}
}