CF2.E
2 seconds
256 megabytes
standard input
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.
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.
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.
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
3
hello test one
ok bye two
a b
a,5,A,0,a,0,A,0,a,0,A,0
2
a
A a A a A
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
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.
题意:
看第一组样例,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的更多相关文章
- 代码问题:【CF2】
[CF2/CFCF/HCF]: C Ma, JB Huang, X Yang, et al. Hierarchical convolutional features for visual tracki ...
- CF2.D
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- CF2.C
C. Vladik and fractions time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CF2.D 并查集+背包
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...
- CF2.BC
B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit ...
- CF2.C(二分贪心)
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- *CF2.D(哥德巴赫猜想)
D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- cf2.25
T1 题意:判断给出的数中有多少不同的大于的数. content:傻逼题,5min手速 T2 题意:给出p.y,输出y~p+1中最大一个不是2-p的倍数的数. content:答案很简单,但是很难想到 ...
- BIRCH聚类算法原理
在K-Means聚类算法原理中,我们讲到了K-Means和Mini Batch K-Means的聚类原理.这里我们再来看看另外一种常见的聚类算法BIRCH.BIRCH算法比较适合于数据量大,类别数K也 ...
随机推荐
- mmap为什么比read/write快(兼论buffercache和pagecache)
参考文献: <从内核文件系统看文件读写过程>http://www.cnblogs.com/huxiao-tee/p/4660352.html?utm_source=tuicool& ...
- 使用NPOI读取Excel报错ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature
写了一个小程序利用NPOI来读取Excel,弹出这样的报错: ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature ...
- monkey工具使用中遇到的问题之二:尝试了各种方法通过adb都无法找到设备
测试环境: 1.用的是adt-bundle-windows-x86_64-20140702里面的adb 2.用的是手机模拟器(夜神) 问题描述: 已搭建好adb的环境,输入adb,可以看到以下相关信息 ...
- 解决ftp上传connection reset错误
切换到管理员,cmd下面执行:netsh advfirewall set global StatefulFTP disable MS对此的解释:https://technet.microsoft.co ...
- JAVA程序中SQL语句无法传递中文参数
vi /etc/my.cnf [mysqld]# The default character set that will be used when a new schema or table is# ...
- 网络请求 __ NSURLSession
首先配置into.plist文件 1. 添加 App Transport Security Settings , Type栏自动变为Dictionary 2. 点击左边箭头,使之向下,点击右边加号,添 ...
- kettle系列-我的开源kettle管理平台[kettle-manager]介绍
kettle管理工具 专门为kettle这款优秀的ETL工具开发的web端管理工具. 项目简介 kettle作为非常优秀的开源ETL工具得到了非常广泛的使用,一般的使用的都是使用客户端操作管理,但问题 ...
- MongoDB聚合运算之mapReduce函数的使用(11)
mapReduce 随着"大数据"概念而流行. 其实mapReduce的概念非常简单, 从功能上说,相当于RDBMS的 group 操作 mapReduce的真正强项在哪? 答:在 ...
- Android studio 自定义打包apk名
Android Studio打包应用默认生成的apk名称是:app-release.apk .如果我们要让生成的apk名跟我们版本包名有联系的话,那我们就要自定义生成的apk名了 需要在build.g ...
- JavaScript call
<script> function dog() { this.sound = "wangwang~"; this.shout = function () { alert ...