Elephant Show
InterviewTime limit1sMemory limit128 MB
Count the yellow tiles reachable from the elephant start by moving up, down, left, or right.
Problem
Chiang Mai has a lot of elephants, and elephant camps can be seen all around the city. Elephant camps are among the most popular attractions in Chiang Mai, but Khun-Lung-Ken Elephant Farm is very different from the others.
At Khun-Lung-Ken Elephant Farm you can enjoy shows performed by elephants such as dancing, playing football and painting. The most interesting one is the show where an elephant eats apples on the ground at high speed. It is held on a rectangular ground covered with big square tiles. Each tile is colored either red or yellow, and every tile has one apple on it. The elephant starts on a yellow tile. From the tile it stands on, it moves to one of the four tiles next to it, horizontally or vertically, never diagonally. The elephant will not step on a red tile, it walks only on yellow tiles, and it never picks up an apple placed on a red tile.
Write a program that counts how many apples the elephant can eat by repeating this move.
Input
The input consists of multiple data sets. Each data set starts with a line containing two positive integers and , the number of tiles in the x direction and the number of tiles in the y direction. Both and are at most 40.
The next lines each contain characters. One character gives the state of one tile.
.: a yellow tile#: a red tileA: an elephant standing on a yellow tile (it appears exactly once in a data set)
The input ends with a line where both and are 0.
Output
For each data set, print on one line the number of tiles the elephant can reach from its starting tile. The starting tile is counted as well.