标签:
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define Maxn 1000
int hang,lie;
char MAP[Maxn][Maxn];
int dir[8][2] = {
{1,0},
{-1,0},
{0,1},
{0,-1},
{1,1},
{1,-1},
{-1,1},
{-1,-1}
};
void dfs(int x,int y)
{
MAP[x][y] = ‘*‘;
for(int i = 0; i < 8; i++)
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx >= 0 && xx < hang && yy >= 0 && yy < lie && MAP[xx][yy] != ‘*‘)
{
dfs(xx,yy);
}
}
}
int main()
{
while(cin >> hang >> lie,hang+lie)
{
int k = 0;
for (int i = 0; i < hang; i++)
{
scanf("%s",MAP[i]);
}
for(int i = 0; i < hang; i++)
{
for(int j = 0; j < lie; j++)
{
if (MAP[i][j] == ‘@‘)
{
dfs(i,j);
k++;
}
}
}
printf("%d\n",k);
}
}
标签:
原文地址:http://www.cnblogs.com/yakoazz/p/5725742.html