#K34622. Comment Formatter
Comment Formatter
Comment Formatter
Given a list of comments with nested replies, write a program to format and print the comments with appropriate indentation. Each comment is represented by an integer id, a user name, and a text message. For each comment, print a line in the format: \(id\ (user):\ text\). Replies to a comment should be indented by two spaces per level.
The input is provided recursively. The first line contains an integer representing the number of top-level comments. For each comment, the following lines are provided in order:
- An integer representing the id.
- A string representing the user (one line).
- A string representing the text message (may contain spaces).
- An integer representing the number of replies.
This structure repeats recursively for each reply.
inputFormat
The input is read from stdin and follows this format:
- The first line contains an integer \(N\) denoting the number of top-level comments.
- For each comment, four components are provided in the following order:
- An integer \(id\).
- A line containing the \(user\) name.
- A line containing the \(text\) message.
- An integer \(R\) denoting the number of replies.
- This structure repeats recursively for each reply.
outputFormat
Output the formatted comments to stdout. Each comment should be printed on its own line in the format:
id (user): text
For replies, indent the line by two spaces for each level of nesting.
## sample1
1
Alice
Hello, world!
0
1 (Alice): Hello, world!