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 |
高手们帮我看下什么数据会runtime error# include <stdio.h> # include <string.h> char seq[10001]; int dp[10001]; int get_depth(int s,int e,int bd,int h){ int p,i,k=1,ns,ne,maxh=h; if(s==e) return bd; for(i=s;i<=e;i++){ if(dp[i]==h) { ns=i; while(dp[++i]!=dp[ns]&&i<=e); ne=i; if((p=get_depth(ns+1,ne-1,bd+k,h+1))>maxh) maxh=p; if(ne==e) break; k++; i=ne-1; } } return maxh; } int main(){ int i,len,th,bh,cur,tn=0; dp[0]=0; while(scanf("%s",&seq),strcmp(seq,"#")){ tn++; cur=bh=th=0; len=strlen(seq); for(i=0;i<len;i++){ if(seq[i]=='d'){ cur++; if(cur>th) th=cur; }else cur--; dp[i+1]=cur; } bh=get_depth(0,len,0,0); printf("Tree %d: %d => %d\n",tn,th,bh); } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator