当前位置:网站首页>3598. 二叉树遍历(华中科技大学考研机试题)
3598. 二叉树遍历(华中科技大学考研机试题)
2022-08-10 21:42:00 【Ray.C.L】

思路:dfs模拟建树
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
void dfs(string pre, string in){
if(pre.empty()) return ;
char root = pre[0];
int k = in.find(root);
dfs(pre.substr(1, k), in.substr(0, k));
dfs(pre.substr(k + 1), in.substr(k + 1));
cout << root ;
}
int main()
{
string pre, in;
while(cin >> pre >> in){
dfs(pre, in);
cout << endl;
}
return 0;
}
边栏推荐
- Black cat takes you to learn Makefile Part 11: When the header file a.h changes, how to recompile all the .c files that depend on the header file a.h
- shell编程之正则表达式与文本处理器
- 力扣215题,数组中的第K个最大元素
- camera preview process --- from HAL to OEM
- 直播课堂系统08-腾讯云对象存储和课程分类管理
- 管理员必须知道的RADIUS认证服务器的部署成本
- 阿里巴巴、蚂蚁集团推出分布式数据库 OceanBase 4.0,单机部署性能超 MySQL
- Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
- An article to teach you a quick start and basic explanation of Pytest, be sure to read
- MySQL高级指令
猜你喜欢

我的世界整合包 云服务器搭建方法(ECS)

unusual understanding

LeetCode-36-Binary search tree and doubly linked list

APP UI自动化测试常见面试题,或许有用呢~

边缘与云计算:哪种解决方案更适合您的连接设备?

高数_复习_第5章:多元函数微分学

Using SylixOS virtual serial port, serial port free implementation system

C # Hex file transfer skills necessary article 】 【 bin file code implementation

黑猫带你学Makefile第13篇:Makefile编译问题合集

12 Recurrent Neural Network RNN2 of Deep Learning
随机推荐
函数:函数删除操作语法&使用例——《mysql 从入门到内卷再到入土》
关于 DataFrame: 处理时间
直播课堂系统08补-腾讯云对象存储和课程分类管理
【SQL刷题】Day3----SQL必会的常用函数专项练习
【PCBA solution】Electronic grip strength tester solution she'ji
GAN CFOP
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
LeetCode-498 - Diagonal Traversal
Conditional Statements of Shell Programming (2)
直播课堂系统08-腾讯云对象存储和课程分类管理
深度学习之 12 循环神经网络RNN2
华为路由器旁挂引流实验(使用流策略)
特别的三杯鸡
水果沙拉酱
每次打开chrome会跳出What's new
2022.8.9 模拟赛
从斐波那契 - 谈及动态规划 - 优化
ENVI最小距离、最大似然、支持向量机遥感影像分类
如何保护 LDAP 目录服务中的用户安全?
Labelme-5.0.1 version edit polygon crash