E. Comments
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.
Input

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.

Output

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.

Examples
input
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
output
3
hello test one
ok bye two
a b
input
a,5,A,0,a,0,A,0,a,0,A,0
output
2
a
A a A a A
input
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
output
4
A K M
B F H L N O
C D G I P
E J
Note

The first example is explained in the statements.

题意:

看第一组样例,hello是顶点,有2个分支,hello的一个分支是ok,ok有0个分支,因此ok后面的bye是hello的一个分支,bye有0个分支,test是顶点,有0个分支,one是顶点,有1个分支,two是one的分支,two有2个分支a,b;

输出每一层的字符串。

代码:

 //这题好麻烦啊。先把字符串转换,每个单词有几个分支。然后暴力。
#include<bits\stdc++.h>
using namespace std;
typedef long long ll;
int a[],b[];
string s[],s1[];
int main()
{
string ch;
cin>>ch;
int len=ch.size();
int cnt=,loca=-,flag1=;
for(int i=;i<len;i++){
if(ch[i]==','){
cnt++;
if(cnt&){
flag1++;
for(int j=loca+;j<i;j++)
s[flag1]+=ch[j];
loca=i;
}
else{
a[flag1]=;
for(int j=loca+;j<i;j++)
a[flag1]=*a[flag1]+ch[j]-'';
loca=i;
}
}
}
int maxn=,tem=;
for(int i=;i<=flag1;i++){
int flag2=;
for(int j=i-;j>tem;j--){
if(a[j]>){
a[j]--;
if(s1[b[j]+].empty())
s1[b[j]+]+=s[i];
else s1[b[j]+]+=+" "+s[i];
b[i]=b[j]+;
flag2=;
break;
}
}
if(!flag2){
b[i]=;
if(s1[].empty())
s1[]+=s[i];
else s1[]+=" "+s[i];
tem=i-;
}
maxn=max(maxn,b[i]);
}
cout<<maxn<<endl;
if(maxn>){
for(int i=;i<=maxn;i++){
cout<<s1[i]<<endl;
}
}
return ;
}

CF2.E的更多相关文章

  1. 代码问题:【CF2】

    [CF2/CFCF/HCF]: C Ma, JB Huang, X Yang, et al. Hierarchical convolutional features for visual tracki ...

  2. CF2.D

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  3. CF2.C

    C. Vladik and fractions time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. CF2.D 并查集+背包

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...

  5. CF2.BC

    B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit ...

  6. CF2.C(二分贪心)

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. *CF2.D(哥德巴赫猜想)

    D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  8. cf2.25

    T1 题意:判断给出的数中有多少不同的大于的数. content:傻逼题,5min手速 T2 题意:给出p.y,输出y~p+1中最大一个不是2-p的倍数的数. content:答案很简单,但是很难想到 ...

  9. BIRCH聚类算法原理

    在K-Means聚类算法原理中,我们讲到了K-Means和Mini Batch K-Means的聚类原理.这里我们再来看看另外一种常见的聚类算法BIRCH.BIRCH算法比较适合于数据量大,类别数K也 ...

随机推荐

  1. select样式美化(简单实用)

    美化select,可以实用一个a标签将select嵌套进去,然后将<a>相对定位,在将select绝对定位,美化<a>即可 文件下载链接:https://i.cnblogs.c ...

  2. APP产品交互设计分析总结(不断更新中...)

    1.首页中的最下方的TAB和中部的TAB的区别 最下面的tab按钮应该是核心级模块级的大功能入口 中间的按钮应该是次核心级页面级的小功能入口 2.对于编辑是在单页内实现好还是跳转到新页面实现好 内容比 ...

  3. ubuntu pycharm 无法 lock from launcher 问题解决

    ubuntu pycharm 无法 lock from launcher 问题解决 最近在自己电脑上安装了python的IDE pycharm, 发现在dash也无法搜索到pycharm的启动图标.( ...

  4. js中== 和===中的区别

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. VS2012 集成 IL DASM IL微软中间语言查看器

    第一步: 找到IL DASM的安装位置,默认在C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools 第二步: ...

  6. Duilib源码分析(一)整体框架

    Duilib界面库是一款由杭州月牙儿网络技术有限公司开发的界面开源库,以viksoe项目下的UiLib库的基础上开发(此后也将对UiLib库进行源码分析):通过XML布局界面,将用户界面和处理逻辑彻底 ...

  7. CollectionView水平和竖直瀑布流的实现

    最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...

  8. 大话css之display的Block未解之谜(一)

    用了几年的css了,css中inline | block |inline-block|table|flex从来没有做过系统的整理和分析,网上的分析文章也很多,零散. 今天有空,就在这做一下整理分析 b ...

  9. openfl使用64位的ndk时,编译报错的问题!

    当使用64位的ndk时,如果使用openfl test android运行android测试,应该会出现 arm-linux-androideabi-g++:找不到这个命令的错误. 原因是,haxel ...

  10. java-并发-同步

    浏览以下内容前,请点击并阅读 声明 线程间的通信主要是通过访问以及对象引用字段,这种形式的通信非常高效,但是会产生两种可能的错误:线程干扰和内存一致性错误,反正这些错误的工具就是同步. 然而,同步可能 ...