#include <bits/stdc++.h>
using namespace std;
char c[25][25];
bool vis[25][25];
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int w, h;
void dfs(int x, int y)
{
if (x < 1 || y < 1 || x > w || y > h || c[x][y] == '#')
{
return;
}
for (int i = 0; i < 4; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
vis[xx][yy] = true;
dfs(xx, yy);
}
}
int main()
{
while(1)
{
cin >> w >> h;
if (w == 0 && h == 0)
{
break;
}
int tmpi, tmpj;
for (int i = 1; i <= h; i++)
{
for (int j = 1; j <= w; j++)
{
cin >> c[i][j];
if (c[i][j] == '@')
{
tmpi = i;
tmpj = j;
}
}
}
memset(vis, false, sizeof(vis));
dfs(tmpi, tmpj);
int ans = 1;
for (int i = 1; i <= w; i++)
{
for (int j = 1; j <= h; j++)
{
if (vis[i][j] == true)
{
ans++;
}
}
}
cout << ans << "\n";
}
return 0;
}
稳定输出1