标签:
Description
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
Hint
#include<cstdio> using namespace std; const int maxn=105; int N,M; char field[maxn][maxn]; void dfs(int x,int y) { field[x][y]='.'; for(int dx=-1; dx<=1; dx++) { for(int dy=-1; dy<=1; dy++) { int nx=x+dx,ny=y+dy; if(nx>=0&&nx<N&&ny>=0&&ny<M&&field[nx][ny]=='W') dfs(nx,ny); } } return ; } int main() { int sum=0; scanf("%d%d",&N,&M); for(int i=0; i<N; i++) scanf("%s",&field[i]);//不能用scanf("%s",&field[i][j]),scanf会读回车,会乱了 for(int i=0; i<N; i++) { for(int j=0; j<M; j++) if(field[i][j]=='W') { dfs(i,j); sum++; } } printf("%d\n",sum); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/a1967919189/article/details/47007437