Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void func(string pre, string in, string &post){
- if(pre.size() == 1){
- post+=pre;
- return;
- }
- int pos = in.find(pre[0]);
- string left = in.substr(0, pos);
- string tl = pre.substr(1, left.size());
- string right = in.substr(pos+1);
- string tr = pre.substr(tl.size()+1);
- //cout << "pos: " << pos << '\n';
- //cout << left << ", " << tl << ", " << right << ", " << tr << '\n';
- if(left.size()>0){
- func(tl, left, post);
- }
- if(right.size()>0){
- func(tr, right, post);
- }
- post+=pre[0];
- }
- int main(){
- //freopen("binarytree.in", "r", stdin);
- string a, b;
- while(cin >> a){
- cin >> b;
- string res = "";
- func(a, b, res);
- cout << res << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement