当前位置:网站首页>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编程之条件语句(二)
企业云存储日常运行维护实践经验分享
配电网络扩展规划:考虑使用概率性能源生产和消费概况的决策(Matlab代码实现)
A shell script the for loop statements, while statement
音乐播放器(未完成版本)
Use Cloudreve to build a private cloud disk
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
德科立科创板上市:年营收7.3亿 市值59亿
随机推荐
新一代网络安全防护体系的五个关键特征
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL
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. Solving Equations】
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
STL-stack
字节跳动原来这么容易就能进去...
Spark基础【RDD转换算子】
mmpose关键点(一):评价指标(PCK,OKS,mAP)
Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
BM13判断一个链表是否为回文结构
基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】
LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
MySQL高级指令
APP UI自动化测试常见面试题,或许有用呢~
Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
自组织是管理者和成员的双向奔赴
What are the concepts, purposes, processes, and testing methods of interface testing?