HUAWEI OD machine test real questions - comment conversion output - 2023 OD unified test (B paper)

Title description: On a blog site, each blog has comments. Each comment is a non-empty string of English letters.
Comments have a tree structure, each comment has a parent comment except the root comment.
When a comment is saved, the following format is used:

  • The first is the content of the comment;
  • Then there is the number of replies to the current comment.
  • And finally all child comments of the current comment. (sub-comments are stored nested using the same format)

All elements are separated by a single comma.
For example, if the comment is as follows:

The first comment is "hello,2,ok,0,bye,0", the second comment is "test,0", and the third comment is "one,1,two,1,a,0".
All comments are saved as "hello,2,ok,0,bye,0,test,0,one,1,two,1,a,0".

For comments in the above format, please print in another format:
first print the maximum depth of comment nesting.
Then print n lines, the i (1<=i<=n) line corresponds to a comment with a nesting level of i (the nesting level of the root comment is 1).
For line i, the comments at nesting level i are printed in the order they appear, separated by spaces.
 

Enter a description: A one-line comment. It consists of English letters, numbers and English commas.

Each comment is guaranteed to be a non-empty string consisting of English characters.

The quantity of each comment is an integer (consisting of at least one number).

The length of the entire string does not exceed 106.

The given comment structure is guaranteed to be legal.

Output description:

Print comments in the given format. For each level of nesting, comments should be printed in the order they appear in the input.

Supplementary note:

Example 1

Supongo que te gusta

Origin blog.csdn.net/2301_76848549/article/details/131558852
Recomendado
Clasificación