#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<vector>#define ll long longusingnamespacestd;stringpre,in,post;intlen;voidpostorder(intlpre,intrpre,intlin,intrin){if(lpre>rpre||lin>rin)return;introotin=lin;while(in[rootin]!=pre[lpre]&&rootin<pre.size())rootin++;intleft=rootin-lin;postorder(lpre+1,lpre+left,lin,rootin-1);postorder(lpre+left+1,rpre,rootin+1,rin);post.push_back(pre[lpre]);}intmain(){while(cin>>pre>>in){post.clear();len=in.length();postorder(0,len-1,0,len-1);cout<<post<<"\n";}return0;}
前序中序求后序
基本都是一个套路