Loading... ![](https://blog.fivk.cn/usr/uploads/2021/07/3918777813.png) ## 题意翻译 输入一棵二叉树的先序遍历和中序遍历序列,输出它的后序遍历序列。 ## 输入输出样例 * **输入样例** ```in DBACEGF ABCDEFG BCAD CBAD ``` - **样例输出** ```out ACBFGED CDAB ``` <div class="panel panel-default collapse-panel box-shadow-wrap-lg"><div class="panel-heading panel-collapse" data-toggle="collapse" data-target="#collapse-6f8f73c5aa41f12510873b83f13c967747" aria-expanded="true"><div class="accordion-toggle"><span style="">【参考程序】</span> <i class="pull-right fontello icon-fw fontello-angle-right"></i> </div> </div> <div class="panel-body collapse-panel-body"> <div id="collapse-6f8f73c5aa41f12510873b83f13c967747" class="collapse collapse-content"><p></p> ```cpp #include<iostream> #include<string> using namespace std; void postorder(string pre,string in) { if(pre.size()<=0) return; int len=in.find(pre[0]); postorder(pre.substr(1,len),in.substr(0,len)); postorder(pre.substr(len+1),in.substr(len+1)); cout<<pre[0]; } int main() { string s1,s2; while(cin>>s1>>s2) { postorder(s1,s2); cout<<endl; } return 0; } ``` <p></p></div></div></div> 最后修改:2021 年 09 月 12 日 © 禁止转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏