洛谷P1030
输入中序先序序列,输出后序
l1-l2为当前中序遍历序列
l3-l4为当前后序遍历序列
#include<bits/stdc++.h>
using namespace std;
string a, b;
struct node{
char self;
int left, right;
}t[200];
void build(int l1, int l2, int l3, int l4) {
for (int i = l1; i <= l2; i++) {
if (a[i] == b[l4]) {
cout << a[i];
build(l1, i-1, l3, l3+i-1-l1);
build(i+1, l2, l3+i-l1, l4-1);
}
}
}
int main() {
cin >> a >> b;
build(0, a.length()-1, 0, a.length()-1);
}
标签:洛谷,后序,int,中序,P1030,先序
From: https://www.cnblogs.com/rjxq/p/18215588