#include "stdio.h"
#include "string.h"
#include "assert.h"
char inorder[30],preorder[30];
void recover(int preleft,int preright,int inleft,int inright){
int root,leftsize,rightsize;
for(root=inleft;root<=inright;root++){
if(inorder[root]==preorder[preleft])break;
}
leftsize=root-inleft;
rightsize=inright-root;
if(leftsize>0)recover(preleft+1,preleft+leftsize,inleft,root-1);
if(rightsize>0)recover(preleft+leftsize+1,preright,root+1,inright);
printf("%c",inorder[root]);
}
void solve_case(){
int n=strlen(preorder);
recover(0,n-1,0,n-1);
printf("\n");
}
int main(){
while(scanf("%s%s",preorder,inorder)!=EOF)solve_case();
return 0;
}
poj 2255
最新推荐文章于 2021-10-16 15:58:38 发布