[Huawei OD Unified Exam B Paper | 200 points] tree structure query (C++ Java JavaScript python)

Huawei OD Online OJ:

Users who have already purchased this column, please private message the blogger to open an account and brush up questions online! ! !

Online OJ: brush the questions immediately

Question bank column: 2023 Huawei OD machine test (A volume + B volume) (C++JavaJSPy)

topic description

Usually use multi-line nodes and parent nodes to represent a tree, such as

Xi'an Shaanxi
Shaanxi China
Jiangxi China
China Asia
Thailand Asia

After entering a node, please print out all his lower nodes in the tree

enter description

Enter the number of lines in the first line, and the following are multiple lines of data. Each line uses a space to distinguish the node from the parent node

followed by the query node

output description

Output all lower nodes of the query node. Sort lexicographically

Remark

The nodes in the tree are unique, there will be no two nodes with the same name

ACM input and output mode

If you often use Leetcode , you will know that letcode does not need to write input and output functions. However, the Huawei OD machine test uses the ACM mode , which requires manual programming of input and output.

So it is best to familiarize yourself with this mode in advance on Niu-ke. For example, C++ uses cin/cout, python usesinput()/print()

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/132642276