///二叉树知道前序、中序输出后序。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define mod 1e9+7
const int maxn=1e5+5;
using namespace std;
char s1[maxn],s2[maxn],ans[maxn];
void build(int n,char*s1,char*s2,char*s)
{
if(n<=0) return;
int p=strchr(s2,s1[0])-s2;
build(p,s1+1,s2,s);
build(n-p-1,s1+p+1,s2+p+1,s+p);
s[n-1]=s1[0];
}
int main()
{
while(scanf("%s%s",s1,s2)){
int n=strlen(s1);
build(n,s1,s2,ans);
ans[n]='\0';
printf("%s\n",ans);
}
return 0;
}
小白+根据前序中序构造后序二叉树
最新推荐文章于 2021-07-25 22:48:01 发布