Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮帮忙 看看哪里错了

Posted by ync at 2005-04-01 19:07:55 on Problem 2386
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator