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

常数最大不会超过8,能帮我看看吗???

Posted by church at 2007-11-02 18:41:37 on Problem 3437
In Reply To:是不是你常数太大了 Posted by:gaosimeng at 2007-11-02 18:22:54
#include <stdio.h>
#include <string.h>

int parent[10005];
int p[10005];
int n;
int frist,last;
char s[10005];


int main()
{
    int i,h,position,pre;
	long k;
	k=0;
	while (1)
	{
		k++;
		scanf("%s",s);
		if (s[0]=='#')
			break;
		printf("Tree %ld: ",k);
		last=0;
		frist=0;  
		h=0;
		n=0;
		position=0;
		p[0]=0;
		for(i=0;i<strlen(s);i++)
			if (s[i]=='d')
			{
				n++;
				h++;
				if (h>frist)
					frist=h;
				parent[n]=position;
				if (i>0 && s[i-1]=='u')
				{
					p[n]=p[pre]+1;
					if (p[n]>last)
						last=p[n];
				}
				else
				{
					p[n]=p[position]+1;
					if (p[n]>last)
						last=p[n];
				}
				position=n;
			}
			else
			{
				pre=position;
				position=parent[position];
				h--;
			}
			printf("%d => %d\n",frist,last);		
	}
	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