#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=27;
char pre_order[maxn],in_order[maxn];
int n;
int build(int l1,int r1,int l2,int r2){
if(l2>r2)return 0;
int root=pre_order[l1];
int u=l2;
while(in_order[u]!=root)++u;
int cnt=u-l2;
build(l1+1,l1+cnt,l2,u-1);
build(l1+cnt+1,r1,u+1,r2);
printf("%c",root);\\\\\\\\\\\\\\\\\\\\\\\\@1
}
int main(){
while(~scanf("%s",pre_order)){
scanf("%s",in_order);
n=strlen(in_order);
build(0,n-1,0,n-1);
printf("\n");
}
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=27;
char pre_order[maxn],in_order[maxn];
int n;
int build(int l1,int r1,int l2,int r2){
if(l2>r2)return 0;
int root=pre_order[l1];
int u=l2;
while(in_order[u]!=root)++u;
int cnt=u-l2;
build(l1+1,l1+cnt,l2,u-1);
build(l1+cnt+1,r1,u+1,r2);
printf("%c",root);\\\\\\\\\\\\\\\\\\\\\\\\@1
}
int main(){
while(~scanf("%s",pre_order)){
scanf("%s",in_order);
n=strlen(in_order);
build(0,n-1,0,n-1);
printf("\n");
}
}
\*
@1:先遍历左子树,后遍历右子树,最后输出根这种方法得到后序遍历
先遍历左子树,后输出根,最后遍历右子树这种方法得到中序遍历
先输出根,后遍历左子树,最后遍历右子树这种方法得到前序遍历
*\