首页 > 代码库 > usaco-3.4-heritage-passed

usaco-3.4-heritage-passed

水题,呵呵:

/*ID: qq104801LANG: C++TASK: heritage*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <queue>#include <stack>#include <algorithm>using namespace std;#define nmax 27int 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]=\0;    cout<<post<<endl;   }int main () {            test();            return 0;}

test data:

USACO TrainingGrader Results     19 users onlineARE/1 AUS/1 BGD/1 CHN/11 IND/2 LTU/1 TWN/1 YUG/1USER: cn tom [qq104801]TASK: heritageLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.011 secs, 3376 KB]   Test 2: TEST OK [0.011 secs, 3376 KB]   Test 3: TEST OK [0.005 secs, 3376 KB]   Test 4: TEST OK [0.008 secs, 3376 KB]   Test 5: TEST OK [0.005 secs, 3376 KB]   Test 6: TEST OK [0.005 secs, 3376 KB]   Test 7: TEST OK [0.005 secs, 3376 KB]   Test 8: TEST OK [0.008 secs, 3376 KB]   Test 9: TEST OK [0.008 secs, 3376 KB]All tests OK.YOUR PROGRAM (‘heritage‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----ABEDFCHGCBADEFGH------- test 2 ----FF------- test 3 ----BCADABCD------- test 4 ----GOLEAFSSFAELOG------- test 5 ----GSHBAQTPMABGHSPQTM------- test 6 ----AUBYCVDZEWFXGTHZYUABVCDXWEFTGH------- test 7 ----ABDCJHKILMNPOQFEGRSABCDEFHJIKLMNOPQGRS------- test 8 ----GFDIHKLJMBNESRTPOQAUCWVZYXABDFGHIJKLMENOPRSTQCUVWXYZ------- test 9 ----EHGDIFJLKMBNCOQSPRAWUXZYTVABDEGHFIJKLMCNOPQSRTUWXYZVKeep up the good work!Thanks for your submission!

 

usaco-3.4-heritage-passed