Tree Recoverynode
#include<bits/stdc++.h> using namespace std; const int maxn = 30; struct node{ char c; struct node* l = NULL; struct node* r = NULL; }; char p[maxn],m[maxn]; node* build_tree(int i,int j,int k){ node* root = new node; root->c = p[k]; if(i == j) return root; int t = i; while(m[t] != p[k]) t++; if(t-1 >= i) root->l = build_tree(i,t-1,k+1); if(t+1 <= j) root->r = build_tree(t+1,j,k+t-i+1); return root; } void post_travel(node* root){ if(!root) return; post_travel(root->l); post_travel(root->r); putchar(root->c); } int main(){ // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); while(scanf("%s %s",p,m) == 2){ int len = strlen(p); node* root = build_tree(0,len-1,0); post_travel(root); putchar('\n'); } return 0; }