| ||||||||||
| 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 | |||||||||
3437 帮忙看一下,不知道错哪了?自己检查不出来#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator