水题,呵呵:
/* ID: qq104801 LANG: C++ TASK: heritage */ #include <iostream> #include <fstream> #include <cstring> #include <vector> #include <queue> #include <stack> #include <algorithm> using namespace std; #define nmax 27 int n,len; char mid[nmax],pre[nmax],post[nmax]; int xindex=0; void getlast(int head,int start,int end) { for(int i=start;i<end;i++) if(mid[i]==pre[head]) { getlast(head+1,start,i); getlast(head+1+i-start,i+1,end); post[xindex]=pre[head]; xindex++; break; } } void test() { freopen("heritage.in","r",stdin); freopen("heritage.out","w",stdout); char str[nmax]; cin>>str; len=strlen(str); for(int i=0;i<len;i++) mid[i]=str[i]; cin>>pre; getlast(0,0,len); post[len]='