http://acm.hdu.edu.cn/showproblem.php?pid=1241
#include<stdio.h>
#include<string.h>
char map[105][105];
int n,m;
void dfs(int x,int y)
{
if(map[x][y]=='*') return;
if(map[x][y]=='@') map[x][y]='*';
if(x<0||y<0||x>=n||y>=m) return;
dfs(x-1,y+1);dfs(x,y+1);dfs(x+1,y+1);
dfs(x-1,y); dfs(x+1,y);
dfs(x-1,y-1);dfs(x,y-1);dfs(x+1,y-1);
}
int main()
{
int cont,i,j;
while(scanf("%d%d",&n,&m),m)
{
cont=0;
getchar();
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%c",&map[i][j]);
getchar();
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(map[i][j]=='@')
cont++;
dfs(i,j);
}
printf("%d\n",cont);
}
return 0;
}