题意:已知先序中序,输出后序。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char pre_order[MAXN];
char in_order[MAXN];
int leftchild[MAXN];
int rightchild[MAXN];
int build(int L1, int R1, int L2, int R2){
if(L1 > R1) return ;
int root = pre_order[L1] - 'A' + ;
int st = L2;
while((in_order[st] - 'A' + ) != root) ++st;
int cnt = st - L2;
leftchild[root] = build(L1 + , L1 + cnt, L2, L2 + cnt - );
rightchild[root] = build(L1 + + cnt, R1, st + , R2);
return root;
}
void dfs(int root){
if(leftchild[root]) dfs(leftchild[root]);
if(rightchild[root]) dfs(rightchild[root]);
printf("%c", root + 'A' - );
}
int main(){
while(scanf("%s", pre_order) != EOF){
scanf("%s", in_order);
int len = strlen(pre_order);
build(, len - , , len - );
int root = pre_order[] - 'A' + ;
dfs(root);
printf("\n");
}
return ;
}

最新文章

  1. 微软“.Net社区虚拟大会”dotnetConf2015 第二天 无处不在的Xamarin
  2. ubutu之jdk安装
  3. wpf 在引用外部的资源字典
  4. CQOI2009中位数图
  5. 使用air进行移动app开发常见功能和问题(一)
  6. Swift中面向协议的编程
  7. Numerical Methods with MATLAB(1)
  8. Hadoop 中关于 map,reduce 数量设置
  9. JavaGUI版本销售管理系统
  10. poj3984迷宫问题(DFS广搜)
  11. 05-Eclispe配置Tomcat插件
  12. python读取excel,返回dic列表
  13. getservbyname和getservbyport
  14. Avito Cool Challenge 2018 自闭记
  15. 如何用Visual Studio 2013 (vs2013)编写C语言程序
  16. platforms
  17. [label][paypal] Paypal 支付页面的语言显示问题
  18. 【BZOJ1226】学校食堂(动态规划,状态压缩)
  19. curl下载文件
  20. HASH表的实现(拉链法)

热门文章

  1. MD5摘要
  2. px(像素)、pt(点)、ppi、dpi、dp、sp之间的关系
  3. [RoarCTF2019]forensic
  4. C# String 字符串一些关键理解
  5. java程序员,英语那点事
  6. python词云图与中文分词
  7. 十 用栈解决LeetCode20题括号的匹配
  8. 初识IntPtr------转载
  9. luogu P3357 最长k可重线段集问题
  10. Day2-J-逃离迷宫-HDU-1728