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

3437 帮忙看一下,不知道错哪了?自己检查不出来

Posted by a7060108 at 2007-11-19 16:06:14
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void count1(char *p,int &dep)
{
	int l=strlen(p),i,len=0,max=0;
	for(i=0;i<l;i++)
	{
		if(p[i]=='d')
		{
			len++;
			if(len>max) max=len;
		}
		else  len--;
	}
	dep=max;
}

int save[500002];
void count2(char *p,int &dep)
{
	int l=strlen(p),i,len=0,max=0,j=0;
	for(i=0;i<l;i++)
		if(p[i]=='d')
		{
			save[j++]=len++;
			if(len>max) max=len;
		}
		else if(p[i+1]=='d')
		{
			i++; len++;
			if(len>max) max=len;
		}
		else
		{
			len=save[--j];
		}
		dep=max;
}


int main()
{
	char a[500002],i=1;
	int depth1,depth2;
	while(scanf("%s",&a) && a[0]!='#')
	{
		count1(a,depth1);
		count2(a,depth2);
		printf("Tree %d: %d => %d\n",i++,depth1,depth2);
	}
	return 0;
}

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