小白+根据前序中序构造后序二叉树
2016-04-30 10:51
309 查看
///二叉树知道前序、中序输出后序。 #include<stdio.h> #include<stdlib.h> #include<iostream> #include<string.h> #include<cstring> #include<string> #include<math.h> #include<algorithm> #define LL long long #define INF 0x3f3f3f3f #define mod 1e9+7 const int maxn=1e5+5; using namespace std; char s1[maxn],s2[maxn],ans[maxn]; void build(int n,char*s1,char*s2,char*s) { if(n<=0) return; int p=strchr(s2,s1[0])-s2; build(p,s1+1,s2,s); build(n-p-1,s1+p+1,s2+p+1,s+p); s[n-1]=s1[0]; } int main() { while(scanf("%s%s",s1,s2)){ int n=strlen(s1); build(n,s1,s2,ans); ans ='\0'; printf("%s\n",ans); } return 0; }
相关文章推荐
- Fresco之服务器的处理
- maya简单的双倍位移节点的创建
- html checkbox多选框语法与结构
- 设计模式概论
- UVA 10305 拓扑排序(基础)
- c++ 智能指针用法详解
- Js中实现网页上导航条的切换功能
- 生成排列
- cojs 西瓜 解题报告
- 1007. 素数对猜想 (20)
- 笔记2:WebRequest 及 WebResponse 类介绍
- 安装Ubuntu时的硬盘分区方案 转载
- Raspberry Pi 配置笔记二
- 吴敬琏:中国经济改革为何出现开倒车现象--From凤凰财经20160430
- 设计模式(一)工厂模式Factory(创建型)
- 北大百练+简单递归回溯+就是那个变量类型弄错了,才搞错的额
- PipelineDraweeControllerBuilder.obtainController()源码分析
- 如何利用XAMPP本地建站的环境配置教程(详细的图文介绍)
- 设计模式(一)工厂模式Factory(创建型)
- NCBI database download