当前位置:网站首页>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;
}
边栏推荐
- 美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
- Web Reverse Lilac Garden
- 【PCBA solution】Electronic grip strength tester solution she'ji
- Shell编程之条件语句(二)
- 3D model reconstruction of UAV images based on motion structure restoration method based on Pix4Dmapper
- HGAME 2022 Week2 writeup by pankas
- GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
- 基于Pix4Dmapper的空间三维模型重建应用——空间分析选址
- 深度学习之 12 循环神经网络RNN2
- LeetCode-498 - Diagonal Traversal
猜你喜欢
JVM经典五十问,这下面试稳了
RADIUS Authentication Server Deployment Costs That Administrators Must Know
爬虫request.get()出现错误
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL
Live Classroom System 08 Supplement - Tencent Cloud Object Storage and Course Classification Management
【PCBA方案设计】蓝牙跳绳方案
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
边缘与云计算:哪种解决方案更适合您的连接设备?
Regular expression of shell programming and text processor
Play RT-THREAD of doxygen
随机推荐
管理员必须知道的RADIUS认证服务器的部署成本
什么是Jmeter?Jmeter使用的原理步骤是什么?
【PCBA方案】电子握力测试仪方案she‘ji
APP UI自动化测试常见面试题,或许有用呢~
ArcMap创建镶嵌数据集、导入栅格图像并修改像元数值显示范围
Play RT-THREAD of doxygen
Conditional Statements of Shell Programming (2)
Shell编程规范与变量
Service - DNS forward and reverse domain name resolution service
Service - DHCP principle and configuration
Extended Chinese Remainder Theorem
直播课堂系统09--腾讯云点播管理模块(一)
【开源教程5】疯壳·开源编队无人机-飞控固件烧写
基于Pix4Dmapper的运动结构恢复法无人机影像三维模型重建
shell编程之正则表达式与文本处理器
翻译科技论文,俄译中怎样效果好
shell(文本打印工具awk)
port forwarding
LeetCode-498 - Diagonal Traversal
特别的三杯鸡