Description: This question is the same as the first example in Liu lujia's book. It is completely recursive, and then AC ...... # Include <iostream> # include <cstring> # include <cstdio> using namespace std; void dfs (int s [110] [110], int row, int clow, int visit [110] [110]) {if (! S [row] [clow] | visit [row-1] [clow-1]) return; visit [row-1] [clow-1] = 1; dfs (s, row-1, clow-1, visit); dfs (s, row-1, clow, visit); dfs (s, row-1, clow + 1, visit ); dfs (s, row, clow-1, visit); dfs (s, row, clow + 1, visit); dfs (s, row + 1, clow-1, visit ); dfs (s, row + 1, clow, visit); dfs (s, row + 1, clow + 1, visit);} int main () {// freopen ("a.txt", "r", stdin); int n, m, I, j, count; int str [110] [110]; int visit_str [110] [110]; char c; while (scanf (" % D ", & n, & m )! = EOF) {if (! N &&! M) break; memset (str, 0, sizeof (str); memset (visit_str, 0, sizeof (visit_str); getchar (); for (I = 0; I <n; I ++) {for (j = 0; j <m; j ++) {scanf ("% c", & c ); if (c = '*') visit_str [I] [j] = 1; if (c = '@') str [I + 1] [j + 1] = 1;} getchar ();} count = 0; for (I = 0; I <n; I ++) for (j = 0; j <m; j ++) if (! Visit_str [I] [j] & str [I + 1] [j + 1]) {count ++; dfs (str, I + 1, j + 1, visit_str);} printf ("% d \ n", count);} return 0 ;}