HDU - 1241
#include<bits/stdc++.h>
using namespace std;
#define maxn 105
char mmp[maxn][maxn];
int t[8][2]= {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
int n,m,sum;
void dfs(int x,int y)
{
int tempx,tempy;
mmp[x][y]='*';
for(int i=0; i<8; i++)
{
tempx=x+t[i][0];
tempy=y+t[i][1];
if(mmp[tempx][tempy]=='@')
{
dfs(tempx,tempy);
}
}
}
int main()
{
while(cin>>n>>m&&n&&m)
{
sum=0;
for(int i=0; i<n; i++)
cin>>mmp[i];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
if(mmp[i][j]=='@')
{
sum++;
dfs(i,j);
}
}
cout<<sum<<endl;
}
return 0;
}