-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem200.java
35 lines (31 loc) · 912 Bytes
/
Problem200.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
import java.util.Scanner;
public class Problem200 {
private static char grid[][];
private static int count = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
grid = new char[n + 1][n];
String line;
for (int i = 1; i <= n; i++) {
line = '*' + scanner.next();
grid[i] = line.toCharArray();
}
int y = scanner.nextInt();
int x = scanner.nextInt();
countEmptyCell(y, x);
System.out.println(count);
scanner.close();
}
private static void countEmptyCell(int y, int x) {
if (grid[y][x] == '*') {
return;
}
count++;
grid[y][x] = '*';
countEmptyCell(y - 1, x);
countEmptyCell(y + 1, x);
countEmptyCell(y, x - 1);
countEmptyCell(y, x + 1);
}
}