lzhh_lzhh26 • 29天前
#include<bits/stdc++.h>
using namespace std;
string s1,s2; //中序 后序
void maketree(int l1,int r1,int l2,int r2){ //1中2后
char root=s2[r2];
for(int f=l1;f<=r1;f++){
if(s1[f]==root){ //中序中找到根节点
cout<<root;
maketree(l1,f-1,l2,l2+(f-1-l1)); //左子树
maketree(f+1,r1,r2-1-(r1-f-1),r2-1); //右子树
}
}
}
int main(){
cin>>s1>>s2;
maketree(0,s1.size()-1,0,s2.size()-1);
return 0;
}
Comments:
请先登录,才能进行评论