There is a rectangular house with square tiles in red and black on the floor. You stand on one of the black tiles and can only move to the adjacent black tile. Please write a program to calculate how many black tiles you can reach in total. Input includes multiple data sets. The first row of each data set is two integers W and H, which represent the number of tiles in the x-direction and y-direction, respectively. W and H are not more than 20. In the next H lines, each line includes W characters. Each character represents the color of a tile, and the rules are as follows:
1)’.’: black tiles;
2)’#’: white tiles ;
3)’@’: A black tile, and you are standing on this tile. This character appears only once in each data set.
When two zeros are read in a row, it means that the input is over.
Output outputs a row for each data set, showing the number of tiles you can reach from the initial position (including the tiles at the initial position when counting). Sample Input
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
0 0
Sample Output
45
BFS can run naked, remember the last +1 (starting position), and then enter the pits. The input is a few columns and rows, not a few rows and several columns< /span>
#include #include #include #include <string> #include #include #include
#include #include #include #include <string> #include #include #include