搜索入门题
//简单dfs
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
char gir[105][105];
int temp[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {0, -1}, {1, 1}, {1, 0}, {1, -1}};
int n, m;
void dfs(int x, int y)
{
int i, xx, yy;
gir[x][y] = '*';
for( i=0; i < 8; i++ )
{
xx = x + temp[i][0];
yy = y + temp[i][1];
if(xx >= 0 && yy >= 0 && xx < n && yy < m)
{
if(gir[xx][yy] == '@')
dfs(xx, yy);
}
}
}
int main()
{
while(scanf("%d%d", &n, &m) != EOF && (n || m))
{
getchar();
int i, j, count = 0;
for( i=0; i < n; i++ )
scanf("%s", gir[i]);
for( i=0; i < n; i++ )
{
for( j=0; j < m; j++ )
{
if(gir[i][j] == '@')
dfs(i, j),count ++;
}
}
printf("%d\n", count);
}
return 0;
}