-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP769.java
More file actions
59 lines (40 loc) · 1.34 KB
/
P769.java
File metadata and controls
59 lines (40 loc) · 1.34 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
package p700_799;
import java.util.Scanner;
//accepted
public class P769 {
public static char[][] cesped;
public static void quitarCesped( int f, int c){
if (cesped[f][c]!='.'){
cesped[f][c]='.';
if (c+1 <cesped[f].length)quitarCesped(f,c+1 );
if (f+1 < cesped.length)quitarCesped(f+1, c);
if (c-1 >= 0)quitarCesped( f, c-1);
if (f-1 >= 0)quitarCesped( f-1, c);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int f = sc.nextInt();
int c = sc.nextInt();
sc.nextLine();
cesped = new char[f][c];
for (int i = 0; i < f; i++) {
String line = sc.nextLine();
for (int j = 0; j < line.length(); j++) {
cesped[i][j] = line.charAt(j);
}
}
int numeroCortacesped = 0;
for (int i = 0; i < cesped.length; i++) {
for (int j = 0; j < cesped[i].length; j++) {
if (cesped[i][j] == '#') {
numeroCortacesped++;
quitarCesped(i, j);
}
}
}
System.out.println(numeroCortacesped);
}
}
}