0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 06:45:26 +00:00

P1827 [USACO3.4]美国血统 American Heritage

R41391823
This commit is contained in:
Baoshuo Ren 2020-11-06 16:50:24 +08:00 committed by Baoshuo Ren
parent e0b7a23c03
commit 5227876e8d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

28
problem/P1827/P1827.cpp Normal file
View File

@ -0,0 +1,28 @@
#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];
int k = in.find(root);
pre.erase(pre.begin());
string leftpre = pre.substr(0, k);
string rightpre = pre.substr(k);
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;
}