Write a program to count the number of black tiles which he can reach by repeating the moves described above.
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)
#include"iostream"
#define N 21
using namespace std;
typedef struct
{int x;
int y;
}node;
node jilu[N*N];
char map[N][N]; //记录该图;
int s1,s2; //记录起始位置;
int s; //记录个数,起始点为1;
int star,end;
int fx[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int h,w;
void BB()
{
s=1;
star=0;
end=1;
node first,next;
jilu[0].x=s1;
jilu[0].y=s2;
map[s1][s2] = '#';//本身就是一个可以的点(即s=1),要将它去掉(防止重复)
while(end!=star)
{
first=jilu[star];
star++; //去掉头个;
for(int i=0;i<4;i++) //判断四个方位是否满足;
{
next.x=first.x+fx[i][0];
next.y=first.y+fx[i][1];
if(next.x>=0 && next.x<h && next.y>=0 && next.y<w && map[next.x][next.y]!='#')
{
s++;
map[next.x][next.y] = '#';
jilu[end]=next;
end++;
}
}
}
cout<<s<<endl;
}
int main()
{
while(cin>>w>>h&&w&&h)
{
for(int j=0;j<h;j++ )
{
for(int k=0;k<w;k++)
{
cin>>map[j][k];
if(map[j][k]=='@')
s1=j,s2=k;
}
}
BB();
}
return 0;
}