#include<stdio.h>
#include<string.h>
void BinaryTreeFromOrderings(char* inorder, char* preorder, int length)
{
if(length == 0)
{
return;
}
char root= *preorder;//root
int rootIndex = 0;
for(;rootIndex < length; rootIndex++)
{
if(inorder[rootIndex] == *preorder)
break;
}
//Left
BinaryTreeFromOrderings(inorder, preorder +1, rootIndex);
//Right
BinaryTreeFromOrderings(inorder + rootIndex + 1, preorder + rootIndex + 1, length - (rootIndex + 1));
printf("%c",root);
return;
}
int main(int argc, char* argv[])
{
char in[30];
char pr[30];
while(~scanf("%s%s",pr,in))
{
BinaryTreeFromOrderings(in, pr, strlen(in));
printf("\n");
}
return 0;
}
/**************************************************************
Problem: 1078
User: kirchhoff
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/