1 #include <iostream> 2 #include <cstdio> 3 char map[21][21]; 4 int H, W, starti, startj, num; //H行 W列 5 int dir[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}}; 6 void dfs(int x, int y) 7 { 8 ++num; 9 for (int i = 0; i < 4; ++i) 10 { 11 int fx = x + dir[i][0]; 12 int fy = y + dir[i][1]; 13 if (fx>=0 && fx<H && fy>=0 && fy<W && map[fx][fy] == '.') 14 { 15 map[fx][fy] = '#'; 16 dfs(fx, fy); 17 } 18 } 19 } 20 int main() 21 { 22 #ifndef ONLINE_JUDGE 23 freopen("in.txt", "r", stdin); 24 #endif 25 while (scanf("%d %d", &W, &H) != EOF && W) 26 { 27 for (int i = 0; i < H; ++i) 28 for (int j = 0; j < W; ++j) 29 { 30 std::cin >> map[i][j]; 31 if (map[i][j] == '@') 32 { 33 starti = i; 34 startj = j; 35 } 36 } 37 map[starti][startj] = '#'; 38 num = 0; 39 dfs(starti, startj); 40 printf("%d\n", num); 41 } 42 return 0; 43 }