深搜水题:
#include <stdio.h>
#include <string.h>
#define LEN 1001
char map[LEN][LEN];
int point[][2] = {{0, 1}, {0, -1}, {1, -1}, {-1, 1}, {1, 1}, {-1, -1}, {1, 0}, {-1, 0}};
int row, col;
void judge(int x, int y) {
int i, j;
int xx, yy;
if('@' == map[x][y]) {
map[x][y] = '.';
}
else {
return;
}
for(i = 0; i < 8; i++) {
xx = x+point[i][0];
yy = y+point[i][1];
if(xx >= 0 && xx < row && yy >= 0 && yy < col) {
judge(xx, yy);
}
}
}
int main() {
int i, j;
int sum;
while(scanf("%d%d", &row, &col), !(0 == row && 0 == col)) {
memset(map, 0, sizeof(map));
for(i = 0; i < row; i++) {
scanf("%s", &map[i]);
}
sum = 0;
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
if('@' == map[i][j]) {
judge(i, j);
++sum;
}
}
}
printf("%d\n", sum);
}
return 0;
}