标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,t,p; char map[105][105]; int yi[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; void dfs(int x,int y) { int i,j,rx,ry; map[x][y]=‘*‘; for (i=0;i<8;i++) { rx=x+yi[i][0]; ry=y+yi[i][1]; if (rx>=1 && rx<=n && ry>=1 && ry<=m && map[rx][ry]==‘@‘) { map[rx][ry]=‘*‘; dfs(rx,ry); } } return ; } int main() { int i,j,ans; while (~scanf("%d%d",&n,&m)) { if (n==0&&m==0) break; ans=0; getchar(); for (i=1;i<=n;i++) for (j=1;j<=m;j++) scanf(" %c",&map[i][j]); for (i=1;i<=n;i++) for (j=1;j<=m;j++) if (map[i][j]==‘@‘) { dfs(i,j); ans++; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/pblr/p/4696385.html