Что я делаю не так для этого проблемного вопроса?

#java

#java

Вопрос:

Я выполняю задание на Hackerrank, и я не могу понять, что я делаю не так, и мой учитель тоже не может. Каждый раз, когда я отправляю свой код, тестовый пример 0 (он не сообщает вам, что он тестирует) завершается с ошибкой. Вот в чем проблема:

 You are helping search and rescue analyze data from their radar to help locate a boat lost at sea. The problem is due to the water not being flat there are a lot of items that appear on the radar that might be a boat, but are not a boat.

Input Format

The first line of input will provide the number of rows and columns for the radar data. The lines after will provide the radar information.

Sample Input
4 3
w w w
w b b
w w w
w b w
Constraints

The data comes in as a 2D array of characters. Water is labelled with the character 'w' and a possible boat has the label 'b'. Fake boats are easy to identify, because they have another boat next to them. The actual boat will only have water next to it. Everything the radar cannot see (the edges of the 2D array) is assumed to be water. Examples (we don't worry about the diagonals):

  w                    b 
w b w    boat        w b w  fake boat
  w                    w
Output Format

Your program will output the row and column where the boat is located (there is at max one boat) or -1, -1 if there is no boat.

Sample Output
3, 1
Sample Input 0

4 3
w w w
w b b
w w w
w b w
Sample Output 0

3, 1
Sample Input 1

3 6
w w w w w w
w b b w w w
w w w w b b
Sample Output 1

-1, -1
  

И вот мой код:

 import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[][] isBoat = new boolean[sc.nextInt()][sc.nextInt()];
        for(int r = 0; r < isBoat.length; r  ) {

            //System.out.println();

            for(int c = 0; c < isBoat[0].length; c  ) {

                isBoat[r][c] = (sc.next().equals("b") ? true : false);
                //System.out.print(isBoat[r][c]   ", ");

            }

        }
        int boatR = -1, boatC = -1;
        for(int r = 0; r < isBoat.length; r  ) {

            //System.out.println();

            for(int c = 0; c < isBoat[0].length; c  ) {

                if(isBoat[r][c]) {
                    boolean above = false, below = false, left = false, right = false;
                    if(r != 0 amp;amp; isBoat[r - 1][c]) {
                        above = true; 
                    }
                    if(r != isBoat.length - 1 amp;amp; isBoat[r   1][c]) { 
                        below = true;
                    }
                    if(c != 0 amp;amp; isBoat[r][c - 1]) { 
                        left = true; 
                    }
                    if(c != isBoat[r].length - 1 amp;amp; isBoat[r][c   1]) { 
                        right = true; 
                    }
                    if(!above amp;amp; !below amp;amp; !left amp;amp; !right) {
                        boatR = r;
                        boatC = c;
                    }

                    //System.out.print((boatR == r amp;amp; boatC == c)   ", ");
                }

            }

        }
        System.out.println(boatR   ", "   boatC);
    }
}
  

Я перепробовал десятки случайно сгенерированных вариантов в Eclipse, и все они сработали. Буду признателен за любую помощь.
Спасибо!

Комментарии:

1. Можем ли мы использовать тестовый пример 0?

2. @Calips Это не говорит вам, что такое тестовый пример… Это упоминается в вопросе…

3. кроме того, приведенный выше код имеет проблемы с компиляцией, отредактируйте свой код

4. @Calips в нем говорится «мы не беспокоимся о диагоналях»

5. @MarcSlothEastman О! спасибо за примечание