diff --git a/problem/P1827/P1827.cpp b/problem/P1827/P1827.cpp new file mode 100644 index 00000000..d43eec77 --- /dev/null +++ b/problem/P1827/P1827.cpp @@ -0,0 +1,28 @@ +#include + +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; +}