UVa 536:Tree Recovery(水题)
2015-09-19 09:22
316 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=477
题意:输入一颗二叉树的先序遍历和中序遍历序列,输出后序遍历序列。(本段摘自《算法竞赛入门经典(第2版)》)
分析:
水题,二叉树的重建。
代码:
题意:输入一颗二叉树的先序遍历和中序遍历序列,输出后序遍历序列。(本段摘自《算法竞赛入门经典(第2版)》)
分析:
水题,二叉树的重建。
代码:
#include <iostream> #include <algorithm> #include <fstream> #include <string> #include <cstring> #include <vector> #include <queue> #include <cmath> #include <cctype> #include <stack> #include <set> #include <map> using namespace std; const int maxn = 100 + 5, INF = 1e9; string a, b; void recovery(string x, string y) { if (x.size() == 0) return; if (x.size() == 1) { cout << x; return; } int pos = y.find(x[0]); recovery(x.substr(1, pos), y.substr(0, pos)); recovery(x.substr(pos + 1), y.substr(pos + 1)); cout << x[0]; } int main() { while (cin >> a >> b) { recovery(a, b); printf("\n"); } return 0; }
相关文章推荐
- MFC 屏蔽esc跟enter键
- 第十一章:集合(二)
- mysql存储引擎innodb和myisam的分析比较
- CRM-POI基础
- Java基础知识强化26:Object类之Object类的概述
- 第十一章:集合(一)
- 软工视频(三)——需求分析
- 第十章:异常处理
- SSID简要介绍
- CAShapeLayer与UIBezierPath
- hdu 1333 Smith Numbers(暴力思路)
- android的5个存储方式
- Android-自定义ViewGroup
- DaveSDK helpcontents
- requirejs的用法
- PHP调试
- MySQL中如何查看“慢查询”,如何分析执行SQL的效率?(转载)
- 为什么编程语言以及数据库要从1970年1月1日开始计算时
- 关于1970-1-1 00:00.000的知识
- BT、电骡、迅雷等P2P下载原理