CF747E.Comments
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.
When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:
- at first, the text of the comment is written;
- after that the number of comments is written, for which this comment is a parent comment (i. e. the number of the replies to this comments);
- after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).
All elements in this format are separated by single comma. Similarly, the comments of the first level are separated by comma.
For example, if the comments look like:

then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:
- at first, print a integer d — the maximum depth of nesting comments;
- after that print d lines, the i-th of them corresponds to nesting level i;
- for the i-th row print comments of nesting level i in the order of their appearance in the Policarp's comments feed, separated by space.
互联网上很少有文章发布后不允许评论。而在 Polycarp 的网站上,每篇文章都配有评论流(comments feed)。
Polycarp 网站上的每条评论均为一个非空字符串,仅由英文字母的大写和小写字母组成。评论具有树状结构,即除根评论(最高层级的评论)外,每条评论恰好有且仅有一个父评论。
当 Polycarp 将评论保存至硬盘时,采用如下格式:每条评论按以下方式书写:
- 首先,写出该条评论的文本内容;
- 其次,写出以该条评论为父评论的子评论数量(即对该条评论的回复数);
- 最后,依次写出所有以该条评论为父评论的子评论(这些子评论的书写也采用完全相同的算法)。
该格式中所有元素均以单个英文逗号分隔。同样地,第一层(根)评论之间也以逗号分隔。
例如,若评论结构如下所示:

则第一条评论写作 "hello,2,ok,0,bye,0",第二条写作 "test,0",第三条写作 "one,1,two,2,a,0,b,0"。整个评论流写作:"hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0"。
给定上述格式的评论流,请将其转换为另一种格式并输出:
- 首先,输出一个整数 d —— 评论嵌套的最大深度;
- 然后,输出 d 行,其中第 i 行对应嵌套深度为 i 的所有评论;
- 对于第 i 行,按其在 Polycarp 评论流中出现的顺序,输出所有深度为 i 的评论,各评论之间以一个空格分隔。
输入格式
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros.
The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.
第一行包含按上述格式给出的非空评论信息流。该信息流由英文字母(大小写)、数字和逗号组成。
保证每条评论均为非空字符串,且仅由英文字母(大小写)构成。每条评论后的数字均为整数(至少包含一位数字),且该整数要么等于 0,要么不包含前导零。
整个字符串的长度不超过 106。保证所给的评论结构是合法的。
输出格式
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
按题目描述中给出的格式输出注释。对于每一层嵌套,注释应按照输入中给出的顺序输出。
输入输出样例
输入#1
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
输出#1
3 hello test one ok bye two a b
输入#2
a,5,A,0,a,0,A,0,a,0,A,0
输出#2
2 a A a A a A
输入#3
A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0
输出#3
4 A K M B F H L N O C D G I P E J
说明/提示
The first example is explained in the statements.
第一个示例在题目描述中已作解释。
输入解题思路,AI测评打分。不知道怎么写?