标签:
Description
D
/
/
B E
/ \
/ \
A C G
/
/
F
Input
Output
Sample Input
DBACEGF ABCDEFG BCAD CBAD
Sample Output
ACBFGED CDAB
Source
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define ll __int64 #define mod 1000000007 #define pi (4*atan(1.0)) const int N=1e5+10,M=1e6+10,inf=1e9+10; char a[100],b[100]; char ans[N]; void dfs(char *a,char *b,char *c,int len) { if(len<=0) return; int n=strlen(b),pos=1; for(int i=0;i<n;i++) { if(b[i]==a[0]) { pos=i; break; } } int l=pos; int r=len-pos-1; dfs(a+1,b,c,l); dfs(a+l+1,b+l+1,c+l,r); c[len-1]=a[0]; } int main() { int x,y,z,i,t; while(~scanf("%s%s",a,b)) { x=strlen(a); dfs(a,b,ans,x); ans[x]=0; cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5598064.html