UVA - 536 Tree Recovery

Description

#include <cstdio>
#include <cstring>
using namespace std;

void postorder(int len, char *pr, char *in, char *po)
{
    if(len <= 0)
        return ;
    int p, i;
    for(i = 0; i < len; i++)
    {
        if(pr[0] == in[i])
        {
            p = i;
            break;
        }
    }
    postorder(p, pr+1, in, po);
    postorder(len-p-1, pr+p+1, in+p+1, po+p);
    po[len-1] = pr[0];
}



int main()
{   int len;char pr[1000], in[1000], po[1000];
    while(scanf("%s %s", pr, in) != EOF)
    {
        len = strlen(pr);
        postorder(len, pr, in, po);
        po[len] = '\0';
        printf("%s\n", po);
    }
    return 0;
}
发布了399 篇原创文章 · 获赞 440 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/Aibiabcheng/article/details/105479908
今日推荐