1 #include <iostream>
 2 #include <cstdio>
 3 char map[101][101];
 4 int m, n;
 5 int dir[8][2] = {{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}};  //八个方向
 6 void dfs(int x, int y)
 7 {
 8     for (int i = 0; i < 8; ++i)
 9     {
10         int fx = x + dir[i][0];
11         int fy = y + dir[i][1];
12         if (fx>=0 && fx<m && fy>=0 && fy<n && map[fx][fy] == '@')
13         {
14             map[fx][fy] = '*';
15             dfs(fx, fy);
16         }
17     }
18 }
19 int main()
20 {
21     while (scanf("%d %d", &m, &n) != EOF && m)
22     {
23         for (int i = 0; i < m; ++i)
24             for (int j = 0; j < n; ++j)
25                 std::cin >> map[i][j];
26         int count = 0;
27         for (int i = 0; i < m; ++i)
28             for (int j = 0; j < n; ++j)
29                 if (map[i][j] == '@')
30                 {
31                     ++count;
32                     dfs(i, j);
33                 }
34         printf("%d\n", count);
35     }
36     system("pause");
37     return 0;
38 }

 

posted on 2013-04-05 14:00  PegasusWang  阅读(385)  评论(0编辑  收藏  举报