/*
ID: niepeng1
PROG: heritage
LANG: C++
*/
#include <iostream>
#include <string.h>
using namespace std;
#define Max1 30
int n;
FILE *in,*out;
struct Node{
Node(){
right=NULL;
left=NULL;
}
char c;
Node *right;
Node *left;
};
int Seek(char ch[],char t)
{
int i;
for( i=0; i<n; i++)
{
if( ch[i] == t)
return i;
}
return -1;
}
void Post(Node *p)
{
if( !p)
return;
Post(p->left);
Post(p->right);
fprintf(out,"%c",p->c);
}
void convert(Node *p,char Pre[],char In[],int lenPre)
{
char *Pre1,*In1,*Pre2,*In2;
int len1,len2;
int i;
i = Seek(In,Pre[0]);
p->c=Pre[0];
Node *q=new Node;
Node *q1=new Node;
Pre1=Pre+1;
Pre2=Pre+1+i;
In1=In;
len1=i;
In2=In+i+1;
len2=lenPre-i-1;
if( i > 0)
{
p->left=q;
convert(q,Pre1,In1,len1);
}
if( i < lenPre -1)
{
p->right=q1;
convert(q1,Pre2,In2,len2);
}
}
int main()
{
char Pre[Max1],In[Max1];
in = fopen ("heritage.in", "r");
out = fopen ("heritage.out", "w");
fscanf(in,"%s %s",In,Pre);
n=strlen(Pre);
Node *p;
p=new Node;
convert(p,Pre,In,n);
Post(p);
fprintf(out,"/n");
fclose(in);fclose(out);
return 1;
}