已知前序遍历和中序遍历,求后序遍历
substr貌似有问题
找不出老来
#include <bits/stdc++.h>
using namespace std;
void f(string a,string b){
int len=a.size();
if (len==0){
return;
}
int pos=a.find(b[0]);
cout<<b[0];
string x=a.substr(0,pos);
string y=b.substr(1,pos);
f(x,y);
x=a.substr(pos+1,len-pos-1);
y=b.substr(pos+1,len-pos-1);
f(x,y);
}
int main(){
string a,b;
while (cin>>a>>b){
f(a,b);
cout<<endl;
}
return 0;
}