文章
85
粉丝
0
获赞
480
访问
9.9k
#include <bits/stdc++.h>
using namespace std;
//前中序建树
string s = "";
void buildPost(string pre ,string in) {
if (pre == "")
return;
char c = pre[0];
int pos = in.find(c);
string new_inleft = in.substr(0,pos);
string new_inright = in.substr(pos+1);
string new_preleft = pre.substr(1,new_inleft.length());
string new_preright = pre.substr(1+new_inleft.length());
buildPost(new_preleft,new_inleft);
buildPost(new_preright,new_inright);
s.push_back(c);
}
int main () {
string pre = "";
string in = "";
while (cin >> pre>>in) {
s="";
buildPost(pre,in);
cout<<s<<endl;
}
}
登录后发布评论
暂无评论,来抢沙发