|
#include <iostream>
#include <cstring>
using namespace std;
int r,s,mx;
char ch[25][25];
bool vis[25][25];
int dr[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
void dfs(int x,int y){
for (int i = 0;i < 4;i++){
int nx = x + dr[0];
int ny = y + dr[1];
if (nx >= 0 && nx < r && ny >= 0 && ny < s && !vis[nx][ny] && ch[nx][ny] == '.'){
vis[nx][ny] = true;
mx++;
dfs(nx,ny);
}
}
}
int main(){
while (cin >> s >> r && r != 0 && s != 0){
memset(vis,false,sizeof(vis));
int x,y;
for (int i = 0;i < r;i++){
for (int j = 0;j < s;j++){
cin >> ch[j];
if(ch[j] == '@'){
x = i;
y = j;
}
}
}
mx = 1;
vis[x][y] = true;
dfs(x,y);
cout << mx << endl;
}
return 0;
}
|
|