<a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=1241">http://acm.hdu.edu.cn/showproblem.php?pid=1241</a>
#include <iostream>
using namespace std;
int dx[] = {0,1,1,1,0,-1,-1,-1}, dy[] = {1,1,0,-1,-1,-1,0,1};
char map[101][101];
int r,c;
void dfs(int x,int y)
{
map[x][y] = '*';
int i,nx,ny;
for(i = 0;i < 8;i++)
{
nx = x + dx[i];
ny = y + dy[i];
if(nx <= r && ny <= c && map[nx][ny] == '@' && nx >= 1 && ny >= 1)
{
dfs(nx,ny);
}
}
return;
}
int main(int argc, char *argv[])
{
while(1)
{
cin >> r >> c;
if(r == 0 && c == 0)
return 0;
int i,j,cnt = 0;
for(i = 1;i <= r;i++)
for(j = 1;j <= c;j++)
cin >> map[i][j];
for(i = 1;i <= r;i++)
for(j = 1;j <= c;j++)
{
if(map[i][j] == '@')
{
dfs(i,j);
cnt++;
}
}
cout << cnt << endl;
}
return 0;
}