标签:
很简单的。
#include<cstdio>#include<iostream>#include<cstdio>#include<cstring>using namespace std;char pic[105][105];void dfs(int x, int y) {if (pic[x][y] == ‘@‘) {pic[x][y] = ‘*‘;dfs(x, y + 1);dfs(x + 1, y);dfs(x + 1, y + 1);if (x > 0) {dfs(x - 1, y);dfs(x - 1, y + 1);if (y > 0) dfs(x - 1, y - 1);}if (y > 0) {dfs(x, y - 1);dfs(x + 1, y - 1);}}}int main() {int m, n;while (scanf("%d%d", &m, &n) == 2 && m && n) {memset(pic, 0, sizeof(pic));for (int i = 0; i != m; ++i) {for (int j = 0; j != n; ++j) {scanf(" %c", &pic[i][j]);}}int ans(0);for (int i = 0; i != m; ++i) {for (int j = 0; j != n; ++j) {if (pic[i][j] == ‘@‘) {dfs(i, j);++ans;}}}printf("%d\n", ans);}return 0;}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4648980.html