uva-536,从先序中序得出后序
来源:互联网 发布:批处理命令安装软件 编辑:程序博客网 时间:2024/06/01 09:55
build右序列的时候粗心,根节点p传错参数了,改了很久才发现
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <iostream>using namespace std;#define DEBUGconst int maxn=26+5,maxv=26;char pre_s[maxn],in_s[maxn];void build(int l,int r,int p,int len){ if(p>=len)return; char c=pre_s[p]; int m=-1; // printf("%c %d %d\n", c,l,r); if(l>r)return; for(int i=l;i<=r;i++) if(in_s[i]==c) m=i; // cout<<m<<endl; // if(m==-1) // printf("%d %d %d %d\n", l,r,m,p); build(l,m-1,p+1,len);build(m+1,r,p+1+m-l,len); // printf("%c\n", c); cout<<c;}int main(){#ifdef DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);#endif while(scanf("%s",pre_s)!=EOF){ scanf("%s",in_s); // cout<<pre_s<<endl; // cout<<in_s<<endl; build(0,strlen(in_s)-1,0,strlen(in_s)); cout<<endl; }#ifdef DEBUG fclose(stdin); fclose(stdout);#endif return 0;}
阅读全文
0 0
- uva-536,从先序中序得出后序
- poj2255:从先序和中序找后序
- 从先序中序重建二叉树输出层序后序
- 从先序遍历和中序遍历重建二叉树
- hashmap hash后得出下标的方法
- 二叉树问题-根据前序遍历结果和中序遍历结果得出后序遍历结果
- 小白书之根据二叉树的先序遍历和中序遍历得出后序遍历
- UVa 536 Tree Recovery (二叉树前序中序生成后序)
- 从先序遍历和中序遍历结果重建二叉树
- java-从先序遍历和中序遍历重建二叉树
- java-从先序遍历和中序遍历重建二叉树
- Construct Binary Tree from Preorder and Inorder Traversal 从先序和中序重建二叉树@LeetCode
- 我在开发网站后得出的asp.Net网站优化总结
- C#编写输入天数后得出多少个月多少周还剩多少天
- 有用!专家对多个软件研发案例反思后,最终得出的12条方法论!
- 用Oracle写分组计算数量后再合计,并得出百分数
- 观察得出
- UVa 548 Tree (中序遍历&后序遍历&DFS)
- 把数组排成最小的数
- 模线性方程组
- WNetAddConnection2 error 1219
- 求二叉树的最大深度
- 关闭当前窗口的方法
- uva-536,从先序中序得出后序
- redis客户端管理之读取xml配置,获取redis链接
- 查看keystore签名信息
- 四大开源协议比较:BSD、Apache、GPL、LGPL
- Redis常用API-使用文档
- python正则如何判断一个字符串中是否只有某些字符
- 7款最流行的在线项目管理工具
- PCA的数学原理(非常值得阅读)!!!!
- Linux那些事(4)-Linux目录杂谈