#K45467. Count Isolated Open Cells
Count Isolated Open Cells
Count Isolated Open Cells
You are given several grids. In each grid, cells are either blocked ('X') or open ('.'). Your task is to count the number of isolated open cells in each grid. An open cell is considered isolated if all four of its adjacent cells (up, down, left, right) are either blocked or lie outside the grid boundaries.
Formally, for a cell at position \((i,j)\) that contains a .
, it is isolated if and only if:
The input terminates when a grid with dimensions 0 0
is encountered. Do not process this terminating grid.
inputFormat
The input consists of one or more grids. For each grid:
- The first line contains two integers n and m (\(1 \leq n, m \leq 1000\)) representing the number of rows and columns respectively.
- The next n lines each contain a string of m characters, where each character is either
X
or.
.
The input ends with a line containing 0 0
, which should not be processed.
outputFormat
For each processed grid, output a single integer on a separate line indicating the count of isolated open cells.
## sample4 4
XXXX
X..X
X..X
XXXX
3 3
XXX
X.X
XXX
5 6
XXXXXX
X....X
XXXXX.
X.....
XXXXXX
0 0
0
1
0
</p>