当前位置:网站首页>3598. Binary tree traversal (Huazhong University of Science and Technology exam questions)
3598. Binary tree traversal (Huazhong University of Science and Technology exam questions)
2022-08-10 22:41: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;
}
边栏推荐
- Shell 编程--Sed
- 艺术与科技的狂欢,阿那亚2022砂之盒沉浸艺术季
- 边缘与云计算:哪种解决方案更适合您的连接设备?
- APP UI自动化测试常见面试题,或许有用呢~
- LeetCode每日一题(1573. Number of Ways to Split a String)
- Conditional Statements of Shell Programming (2)
- H3C S5130 IRF做堆叠
- Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
- 元宇宙社交应用,靠什么吸引用户「为爱发电」?
- 【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
猜你喜欢

shell脚本

链表相加(二)

Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?

【640. 求解方程】

What is Jmeter? What are the principle steps used by Jmeter?

如何成为一名正义黑客?你应该学习什么?

测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?

翻译科技论文,俄译中怎样效果好

阿里云张新涛:支持沉浸式体验应用快速落地,阿里云云XR平台发布

计算需要的MIPI lane数目
随机推荐
瑞幸咖啡第二季营收33亿:门店达7195家 更换CFO
德科立科创板上市:年营收7.3亿 市值59亿
特别的三杯鸡
2022.8.8 Selected Lectures on Good Topics (Number Theory Field)
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
什么是Jmeter?Jmeter使用的原理步骤是什么?
商家招募电商主播要考虑哪些内容
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
STL-stack
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL
QT笔记——用VS + qt 生成dll 和 调用生成的dll
服务——DHCP原理与配置
ThreadLocal comprehensive analysis (1)
12 Recurrent Neural Network RNN2 of Deep Learning
An article to teach you a quick start and basic explanation of Pytest, be sure to read
黑猫带你学Makefile第13篇:Makefile编译问题合集
VLAN huawei 三种模式
企业云存储日常运行维护实践经验分享
LeetCode Daily Question (1573. Number of Ways to Split a String)