Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮帮忙 看看哪里错了#include<stdio.h> #include<string.h> char A[105][105]; int N,M; void recur(int i,int j) { A[i][j]='W'; if(i>1&&A[i-1][j]=='.') recur(i-1,j); if(i>1&&j>1&&A[i-1][j-1]=='.') recur(i-1,j-1); if(j>1&&A[i][j-1]=='.') recur(i,j-1); if(i<N&&j>1&&A[i+1][j-1]=='.') recur(i+1,j-1); if(i<N&&A[i+1][j]=='.') recur(i+1,j); if(i<N&&j<M&&A[i+1][j+1]=='.') recur(i+1,j+1); if(j<M&&A[i][j+1]=='.') recur(i,j+1); if(i>1&&j<M&&A[i-1][j+1]=='.') recur(i-1,j+1); return ; } int main() { int i,j,block; while(1) { scanf("%d%d",&N,&M); for(i=1;i<=N;i++) { scanf("%s",A[i]+1); } block=0; for(i=1;i<=N;i++) { for(j=1;j<=M;j++) { if(A[i][j]=='W') continue; block++; recur(i,j); } } printf("%d\n",block); break; }//while return 0; } /* N x M (1 <= N <= 100; 1 <= M <= 100) 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 */ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator