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

求大牛解释啊。。。。。。。。奇怪地A掉 花括号的问题!

Posted by starkerry at 2011-02-22 21:43:10 on Problem 3051
#include <iostream>
#include <cstring>
#include <algorithm>
#define max 7000
int da[max];
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
char grid[max][max];
int m,n,num=0;
void dfs(int x,int y)
{
	if(grid[x][y]=='.')
		return ;
	grid[x][y]='.';
	dfs(x-1,y);
	dfs(x+1,y);
	dfs(x,y+1);
	dfs(x,y-1);
	da[num]++;
}
int main ()
{	
		int i,j,sum=0;
		while (scanf ("%d%d",&m,&n)==2)
		memset(grid,'.',max * max * sizeof(char));
		memset(da,0,sizeof(da));
		for(i=1;i<=n;i++)
		{
			for (j=1;j<=m;j++)
				grid[i][j]=getchar();
			if (i!=n)
				getchar();
		}
		for (i=1;i<=n;i++)
		{
			for (j=1;j<=m;j++)
				if(grid[i][j]=='*')
				{
					dfs(i,j);
					num++;
				}
		}
		sort(&da[0],&da[max],cmp);
		printf("%d\n",da[0]);
	return 0;
}


为什么在while(scanf)这一句后加了个花括号为什么答案都错了,没加却A掉了?

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