当前位置:网站首页>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;
}
边栏推荐
- 3D model reconstruction of UAV images based on motion structure restoration method based on Pix4Dmapper
- SDP
- Likou 221 questions, the largest square
- 过滤器
- GAN CFOP
- Live Classroom System 09--Tencent Cloud VOD Management Module (1)
- shell programming without interaction
- 翻译科技论文,俄译中怎样效果好
- What are the concepts, purposes, processes, and testing methods of interface testing?
- 带着昇腾去旅行:一日看尽金陵城里的AI胜景
猜你喜欢

Shell programming specification and variables

unusual understanding

【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示

Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL

camera预览流程 --- 从HAL到OEM

Play RT-THREAD of doxygen

JVM classic fifty questions, now the interview is stable

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

xshell (sed 命令)

shell (text printing tool awk)
随机推荐
Intelligent scheme design - intelligent rope skipping scheme
黑猫带你学Makefile第12篇:常见Makefile问题汇总
C#【必备技能篇】Hex文件转bin文件的代码实现
labelme-屏蔽拖拽的事件
About DataFrame: Processing Time
RADIUS Authentication Server Deployment Costs That Administrators Must Know
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
JVM classic fifty questions, now the interview is stable
Using SylixOS virtual serial port, serial port free implementation system
shell (text printing tool awk)
VLAN huawei 三种模式
函数:函数删除操作语法&使用例——《mysql 从入门到内卷再到入土》
QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍
mmpose关键点(一):评价指标(PCK,OKS,mAP)
What is Jmeter? What are the principle steps used by Jmeter?
新一代网络安全防护体系的五个关键特征
ENVI最小距离、最大似然、支持向量机遥感影像分类
国内Gravatar头像的完美替代方案Cravatar
shell脚本
我的世界整合包 云服务器搭建方法(ECS)