Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class t200 {
- static Scanner in = new Scanner(System.in);
- static int n = in.nextInt();
- static int [][] a = new int [n+2][n+2];
- static int k = 1;
- public static void dfs(int s, int e) {
- a[s][e] = 0;
- if(a[s-1][e] == 1) {
- k++;
- dfs(s-1, e);
- }
- if(a[s+1][e] == 1) {
- k++;
- dfs(s+1, e);
- }
- if(a[s][e-1] == 1) {
- k++;
- dfs(s, e-1);
- }
- if(a[s][e+1] == 1) {
- k++;
- dfs(s, e+1);
- }
- }
- public static void main(String[] args) {
- String command;
- for (int i = 1; i < n+1; i++) {
- command = in.next();
- char [] chArray = command.toCharArray();
- for (int j = 0; j < n; j++) {
- if(chArray[j] == '.')
- a[i][j+1] = 1;
- else
- a[i][j+1] = 0;
- }
- }
- int s = in.nextInt();
- int e = in.nextInt();
- dfs(s, e);
- System.out.println(k);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement