#include <iostream> #include <stdio.h> #include <cstring> using namespace std; char tiles[22][22]; int used[22][22]; int count, w, h; void countstep(int i, int j) { count ++; if (i > 1 && used[i-1][j] == 0) //向上 { used[i-1][j] = 1; countstep(i-1, j); } if (i < h && used[i + 1][j] == 0) //向下 { used[i+1][j] = 1; countstep(i+1, j); } if (j > 0 && used[i][j-1] == 0) //向左 { used[i][j-1] = 1; countstep(i, j-1); } if (j < w-1 && used[i][j+1] == 0) //向右 { used[i][j+1] = 1; countstep(i, j+1); } } int main() { int starti, startj; while (scanf("%d %d", &w, &h) != EOF) { if (w == 0 || h == 0) break; count = 0; memset(used, 0, sizeof(used)); for (int i = 1; i <= h; i++) { scanf("%s", &tiles[i]); } for(int i = 1; i <= h; i++) { for (int j = 0; j < w; j++) { if (tiles[i][j] == '#') used[i][j] = 1; else if (tiles[i][j] == '@') { used[i][j] = 1; startj = j; starti = i; } } } countstep(starti, startj); printf("%d\n", count); } }