#include <iostream>
using namespace std;
void dfs(string a, string b)
{
if(!b.length())//当排列遍历结束时返回
return;
cout << b[b.length() - 1];
int t = a.find(b[b.length() - 1]);//在后序排列中找根结点
dfs(a.substr(0, t), b.substr(0, t));//递归左子树
dfs(a.substr(t + 1), b.substr(t, b.length() - 1 - t));//递归右子树
}
int main(){
string a, b;
cin >> a >> b;
dfs(a, b);
return 0;
}
t 好像是中序排列的根节点位置,后序排列的根节点位置在末尾。
我那句话自己表达不清楚没说完,我意思是b[b.length() - 1] 是后序排列的最后一个元素是根节点