第1个回答 2013-03-19
#include <iostream>
#include <string>
using namespace std;
string pre;
void preorder(string a,string b)
{
if(b.length()==1) {pre+=b;}
else
{
int k=a.find(b.substr(b.length()-1,1));
pre+=a[k];
if (k>0)
preorder(a.substr(0,k),b.substr(0,k));
if (k<a.length()-1)
preorder(a.substr(k+1,a.length()-k-1),b.substr(k,b.length()-k-1));
}
}
void main()
{
string a,b;
cout<<"input string a:";
cin>>a;
cout<<"input string b:";
cin>>b;
preorder(a,b);
cout<<pre<<endl;
}