Tree Recovery
#include <cmath>
#include <iostream>
#include <queue>
#define LL long long
using namespace std;
string s1,s2;
int p=1;
struct Node{
char c;
Node* L;
Node* R;
};
Node* creatTree(int l,int r,char c){
Node* t=new Node;
t->c=c;t->R=NULL,t->L=NULL;
if(l==r) return t;
for(int i=l;i<=r;i++){
if(s2[i]==c){
if(l<=i-1)
t->L=creatTree(l,i-1,s1[p++]);
if(i+1<=r)
t->R=creatTree(i+1,r,s1[p++]);
}
}
return t;
}
void oo(Node *root){
if(root!=NULL){
oo(root->L);
oo(root->R);
cout << root->c;
}
}
int main(){
while(cin >> s1){
cin >>s2;
Node* root=creatTree(0,s2.size()-1,s1[0]);
p=1;
oo(root);
cout << endl;
}
return 0;
}