文章
17
粉丝
166
获赞
6
访问
143.2k
#include <bits/stdc++.h>
using namespace std;
vector<char> pre, in, post;
int cnt;
string a,b;
void recons(int l, int r)
{
if(l >= r) return;
char root = pre[cnt++];
int m = distance(in.begin(), find(in.begin(), in.end(), root));
recons(l, m);
recons(m + 1, r);
post.push_back(root);
}
int main()
{
while(cin >> a >> b)
{
cnt = 0;
pre.clear();in.clear();post.clear();
for(int i = 0; i < a.size(); i++)
{
pre.push_back(a[i]);
in.push_back(b[i]);
}
recons(0, a.size());
for(auto c: post) cout << c;
cout << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发