POJ2255
#include<iostream> #include<cstdio> #include<string.h> using namespace std; void postorder(char *prestart,char *preend,char *instart,char *inend) { char root=*prestart; int len=preend-prestart; int i; for(i=0;*(instart+i)!=root&&i<=len;i++); if(i!=0)postorder(prestart+1,prestart+i,instart,instart+i-1); if(i!=len)postorder(prestart+i+1,preend,instart+i+1,inend); if(root!=0)printf("%c",root); } int main() { char preorder[27],inorder[27]; while(scanf("%s",preorder)!=EOF) { scanf("%s",inorder); int len=strlen(preorder); postorder(preorder,preorder+len,inorder,inorder+len); printf("\n"); } return 0; }