PAT真题1174 Left-View of Binary Tree (25分)

该博客介绍了PAT考试中的一道题目,即根据二叉树的中序和前序遍历序列求解其左视图。左视图是从树的左侧自上而下看到的节点序列。博客提供了一个例子,展示了如何从给定的遍历序列得到左视图,例如{1, 2, 3, 4, 5}。题目要求输出符合条件的二叉树的左视图,并给出样例输入和输出。文章可能包含解题思路和代码实现。" 103326943,6624774,Python接口自动化测试框架中的继承与多态,"['Python', '自动化测试框架', '面向对象编程', '继承', '多态']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1174 Left-View of Binary Tree (25分)

The left-view of a binary tree is a list of nodes obtained by looking at the tree from left hand side and from top down. For example, given a tree shown by the figure, its left-view is { 1, 2, 3, 4, 5 }

Given the inorder and preorder traversal sequences of a binary tree, you are supposed to output its left-view.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer N (≤20), which is the total number of nodes in the tree. Then given in the following 2 lines are the inorder and preorder traversal sequences of the tree, respectively. All the keys in the tree are distinct positive integers in the range of int.

Output Specification:

For each case, print in a line the left-view of the tree. All the numbers in a line are separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

Sample Input:

8
2 3 1 5 4 7 8 6
1 2 3 6 7 4 5 8
1
2
3

Sample Output:

1 2 3 4 5

题目转载:https://blog.csdn.net/qq_40805977/article/details/115721071

代码

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int pro[50005];
int inor[50005]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值