0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 03:18:48 +00:00
OI-codes/Luogu/P1827/P1827.cpp

29 lines
559 B
C++
Raw Normal View History

#include <bits/stdc++.h>
using namespace std;
string pre, in, post;
void dfs(string pre, string in) {
if (pre.empty()) {
return;
}
char root = pre[0];
2021-11-19 09:01:13 +00:00
int k = in.find(root);
pre.erase(pre.begin());
2021-11-19 09:01:13 +00:00
string leftpre = pre.substr(0, k);
string rightpre = pre.substr(k);
2021-11-19 09:01:13 +00:00
string leftin = in.substr(0, k);
string rightin = in.substr(k + 1);
dfs(leftpre, leftin);
dfs(rightpre, rightin);
post.push_back(root);
}
int main() {
cin >> in >> pre;
dfs(pre, in);
cout << post << endl;
return 0;
}