#include <iostream> #include <string> using namespace std; struct node { char val; node *left, *right; node(char x) : val(x), left(NULL), right(NULL) {} }; string pre, in; node* Create(int preL, int preR, int inL, int inR){ if(preL > preR){ return NULL; } node* root = new node(pre[preL]); int k; for(k = inL; k <= inR; k++){ if(in[k] == pre[preL]){ break; } } int numLeft = k - inL; root->left = Create(preL + 1, preL + numLeft, inL, k - 1); root->right = Create(preL + numLeft + 1, preR, k + 1, inR); return root; } void postOrder(node* root){ if(root == NULL){ return; } postOrder(root->left); postOrder(root->right); cout << root->val; } int main() { while(cin >> pre >> in){ node* root = Create(0, pre.length() - 1, 0, in.length() - 1); postOrder(root); cout << endl; } return 0; }