当前位置:网站首页>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;
}
边栏推荐
- LabVIEW分配多少线程?
- win系统下pytorch深度学习环境安装
- 合并k个已排序的链表
- JVM classic fifty questions, now the interview is stable
- JS中使用正则表达式g模式和非g模式的区别
- 阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
- 翻译科技论文,俄译中怎样效果好
- 【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
- 边缘与云计算:哪种解决方案更适合您的连接设备?
- [Maui official version] Create a cross-platform Maui program, as well as the implementation and demonstration of dependency injection and MVVM two-way binding
猜你喜欢
Nodes in the linked list are flipped in groups of k
诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
OneNote 教程,如何在 OneNote 中整理笔记本?
unusual understanding
高数_复习_第5章:多元函数微分学
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
Thread State 详解
The Thread State,
win系统下pytorch深度学习环境安装
"DevOps Night Talk" - Pilot - Introduction to CNCF Open Source DevOps Project DevStream - feat. PMC member Hu Tao
随机推荐
STL-stack
How to secure users in LDAP directory service?
Service - DHCP principle and configuration
The Thread State,
SDP
“数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
Service - DNS forward and reverse domain name resolution service
翻译科技论文,俄译中怎样效果好
MySQL高级指令
元宇宙社交应用,靠什么吸引用户「为爱发电」?
企业云存储日常运行维护实践经验分享
ThreadLocal全面解析(一)
BM7 链表中环的入口结点
A shell script the for loop statements, while statement
An article to teach you a quick start and basic explanation of Pytest, be sure to read
MySQL:MySQL的集群——主从复制的原理和配置
【640. 求解方程】
Black cats take you learn Makefile article 13: a Makefile collection compile problem
STL-deque
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛