Tree Recovery-UVA 536
2015-07-19 09:24
387 查看
代码比较简洁,记录一下。
#include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cstdlib> #include <cstdio> #include <string> #include <vector> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> using namespace std; int s1[100],s2[100]; void build(int l1,int r1,int l2,int r2){ if(l2>r2) return; int root=s1[l1]; int p=l2; while (s2[p]!=root) p++; int cnt=p-l2; build(l1+1, l1+cnt,l2,p-1); build(l1+cnt+1, r1, p+1, r2); cout<<(char) root; } int main(){ string pre,in; while (cin>>pre>>in) { int lenth=pre.size(); for (int i=0; i<lenth; i++) { s1[i]=pre[i]; s2[i]=in[i]; } build(0, lenth-1, 0, lenth-1); cout<<endl; } return 0; }
相关文章推荐
- 那些神奇的"大师"是如何炼成的(科学、迷信、心理)
- Android Fragment
- 敏捷开发之Scrum扫盲篇
- 嵌入式学习答疑
- Android之——Handler随笔
- Merge Two Sorted Lists
- poj1649 Rescue(BFS+优先队列)
- (win8系统)VMware-workstation安装教程(图文)
- java虚拟机学习笔记 一
- 《textanalytics》课程简单总结(4):课程总结
- 三次面试总结
- [LeetCode] Longest Palindrome Substring 具体分析
- UIPopoverController和UIActionSheet在iPad中使用
- 7.18使用<a>标签
- cocos2d-x-3.1.1工程创建
- TCP/IP网络简介(来自与51CTO学院视频授课内容)
- 7.16日table学习笔记
- php开发之数组排序
- 7.15<br/><hr/><code><ul><li>学习笔记
- 良苦用心