Oooh I See
InterviewTime limit1sMemory limit2048 MB
Given a grid of O and 0 characters, find every 0 whose eight neighbors are all O, then print its position, the count, or Oh no!.
- Level
Easy2 of 10
- Topics
- Matrix, Brute force
- Solved
- No attempts yet
Problem
Captain O'Capten hid some treasure and drew a map marking where it is buried. Instead of marking the spot with an X, he hid the location in a grid of uppercase O letters and 0 digits. The treasure is at a 0 character whose eight neighbors, above, below, left, right, and the four diagonals, are all O characters. Captain O'Capten wants to find the treasure, but his map is hard to read (no surprise there).
Input
The first line contains two integers and (), the number of rows and columns on the map. The next lines each contain characters, each either O or 0. Rows are numbered 1 to from top to bottom, and columns are numbered 1 to from left to right.
Output
If no 0 character is surrounded on all sides by 8 O characters, print Oh no! on one line. If more than one such 0 exists, print Oh no! N locations, with N replaced by the count. If exactly one exists, print its row number and column number on one line, separated by a space.