#include<cstdio> #include<queue> #include<cstring> using namespace std; //简单bfs开始把行列搞错了 struct Node { int x; int y;//坐标 int cnt;//步数 Node(int a,int b,int c):x(a),y(b),cnt(c) {} }; char rec[30][30]; int w,h,x1,y1; int nowx,nowy,nowc; bool vis[30][30]; int direction[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; //上下左右 queue<Node> q; int bfs(int x,int y) { int ans = 1; q.push(Node(x,y,1)); vis[x][y] = 1; while(!q.empty()) { Node now = q.front(); q.pop(); for(int i = 0; i<4; ++i) { x1 = now.x + direction[i][0]; y1 = now.y + direction[i][1]; if(x1<h&&x1>=0&&y1<w&&y1>=0&&rec[x1][y1]!='#'&&!vis[x1][y1]) { q.push(Node(x1,y1,now.cnt+1)); ans++; vis[x1][y1] = 1; } } } return ans; } int main() { char c; int x,y; while(scanf("%d%d",&w,&h),w) { memset(vis,0,sizeof(vis)); for(int i = 0; i<h; ++i) { getchar(); for(int j = 0; j<w; ++j) { scanf("%c",&rec[i][j]); if(rec[i][j]=='@') { x = i; y = j; } } } printf("%d\n",bfs(x,y)); } return 0; }