| ||||||||||
| 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??高手麻烦给看一下,如果找到错误,发封mail给我,谢谢了!#include <iostream>
#include <fstream>
using namespace std;
char preorder[30];
char inorder[30];
int len;
char post[30];
int postlen;
void func(const char *pre,const char *in){
char pltree[30],prtree[30];int pln=0,prn=0;
char iltree[30],irtree[30];int iln=0,irn=0;
int curlen=strlen(pre);
char root=pre[0];
post[postlen--]=root;
if(curlen==1)return;
else if(curlen==2){
post[postlen--]=pre[1];
return;
}
for(int i=0;i<curlen;i++){
if(in[i]==root)break;
}
if(i==0){
for(int k=1;k<=len;k++){
prtree[prn++]=pre[k];
irtree[irn++]=in[k];
}
prtree[prn]='\0';irtree[irn]='\0';
func(prtree,irtree);
return;
}
for(int j=1;j<=i;j++){
pltree[pln++]=pre[j];
}
for(j=i+1;j<curlen;j++){
prtree[prn++]=pre[j];
}
pltree[pln]='\0';prtree[prn]='\0';
for(j=0;j<i;j++){
iltree[iln++]=in[j];
}
for(j=i+1;j<curlen;j++){
irtree[irn++]=in[j];
}
iltree[iln]='\0';irtree[irn]='\0';
func(prtree,irtree);
func(pltree,iltree);
}
void main(){
// ifstream cin("data.txt");
while(1){
cin>>preorder>>inorder;
if(strcmp(preorder,"")==0)break;
len=strlen(preorder);
postlen=len;
post[len+1]='\0';
func(preorder,inorder);
for(int i=1;i<=len;i++)
cout<<post[i];
cout<<endl;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator