紫书UVA 536

#include<bits/stdc++.h>
using namespace std;
typedef struct node * tree;
typedef struct node
{
    tree rchild;
    tree lchild;
    char data;
}node;
tree dfs(char *in,char *pre,int length)
{
    if(length<=0)
        return NULL;
    tree t=new node;
    int root=0;
    t->data=*pre;
    for(;root<length;root++)
    {
        if(in[root]==*pre)
        {
            break;
        }
    }
    t->lchild=dfs(in,pre+1,root);
    t->rchild=dfs(in+root+1,pre+root+1,length-root-1);
    cout<<t->data;
    return t;
}
int main()
{
    char in[27],pre[27];
    while(cin>>pre>>in)
    {
        dfs(in,pre,strlen(in));
        cout<<endl;
    }
    return 0;

}


posted @ 2018-05-02 15:35  MCQ  阅读(87)  评论(0编辑  收藏  举报