uva536 Tree Recovery

已知前序中序求后序

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
string po;
void Computing(string pre,string in)
{
    int len=pre.length();
    if(len>0){
        int p=(int)(in.find(pre[0]));
        Computing(pre.substr(1,p),in.substr(0,p));
        Computing(pre.substr(p+1,len-p-1),in.substr(p+1,len-p));
        po.push_back(pre[0]);
    }
}
int main()
{
    string pre,in;
    while(cin>>pre>>in){
        Computing(pre,in);
        cout<<po<<endl;
        pre.clear();in.clear();po.clear();
    }
    return 0;
}


posted @ 2014-10-29 19:33  Scale_the_heights  阅读(138)  评论(0编辑  收藏  举报