#T373. 红与黑
红与黑
Description
There is a rectangular room covered with square tiles in two colors: red and black. You are standing on one of the black tiles and can only move to adjacent black tiles. Write a program to calculate the total number of black tiles you can reach.
Input Format
The input consists of multiple datasets. The first line of each dataset contains two integers, W and H, representing the number of tiles in the x and y directions, respectively. Neither W nor H exceeds 20. The following H lines each contain W characters. Each character represents the color of a tile, with the following rules:
- '.': a black tile;
- '#': a white tile;
- '@': a black tile, and you are standing on this tile. This character appears exactly once in each dataset.
When a line with two zeros is read, the input ends.
Output Format
For each dataset, output a line displaying the number of tiles you can reach from the initial position (including the initial tile in the count).
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
0 0
45