问题类型:树的遍历,DFS。
问题链接
03pie’s solution for [UVA-536]:
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=26+1;
char fT[maxn];
char mT[maxn];
void dfs(int l1,int r1,int l2,int r2,int pos){
if(l1>r1) return;
while(fT[l1]!=mT[pos]) pos++;
dfs(l1+1,l1+pos-l2,l2,pos-1,0);
dfs(l1+pos+1-l2,r1,pos+1,r2,0);
cout<<mT[pos];
}
int main(){
while(cin>>fT>>mT){
int len=strlen(mT)-1;
dfs(0,len,0,len,0);
cout<<endl;
}
return 0;
}