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也 ...
随机推荐
- silverlight 流程设计器,流程引擎
(图一流程设计器包含元素) (图一流程设计器实现功能) (流程引擎工作原理) (流程数据库设计) (流程数据库设计) (流程数据库设计) (工作流程设计器实现效果图) (代码结构图) 无法上传附件,需 ...
- Linux学习记录
---恢复内容开始--- linux与unix的关系 linux是借鉴了unix设计思想,也称linux位类unix系统. Linux常用命令 1.命令基本格式 命令[选项][参数] 注意:个别命令不 ...
- AngularJS2
//package.json 用来标记本项目所需的npm依赖包{ "name": "angular-quickstart", "version&quo ...
- MYSQL数据库相关知识合集
1 MYSQL取得某一范围随机数: 关键词:RAND() [产生0~1之间的随机数] mysql> SELECT RAND( ), RAND( ), RAND( ); +----------- ...
- JS 模块化和打包方案收集
1.这里想讨论的是拆分规则,不是在问哪个工具怎么使用.2.这里没有在想找正确答案,因为感觉这个问题要结合具体业务场景. 随着项目开发越来越大,一开始代码全打包到一个文件的方式,让文件越来越大,接下来要 ...
- C++ 系列:内存布局
转载自http://www.cnblogs.com/skynet/archive/2011/03/07/1975479.html 为什么需要知道C/C++的内存布局和在哪可以可以找到想要的数据?知道内 ...
- C#远程时间同步助手软件设计
C#远程时间同步助手软件设计 本程序才C#语言开发,实现远程时间同步功能,可以将本地时间每隔一段时间与时间服务器时间进行同步!不足之处还望见谅! 软件开发环境:Visual Studio 2010 软 ...
- 【leetcode】Compare Version Numbers
题目描述: Compare two version numbers version1 and version2. If version1 > version2 return 1, if vers ...
- 第三十一篇:SOUI布局之相对于特定兄弟窗口
SOUI中通过pos的标志如:[, {, }, ],这4个标志可以相对于前一个及后一个兄弟窗口,但是有时候希望相对于不是前后窗口的兄弟窗口,比如一个通过一个中心窗口同时定义它的上下左右4个窗口,这个时 ...
- Android网络定位服务定制简述
Android 添加高德或百度网络定位服务 Android的网络定位服务以第三方的APK方式提供服务,由于在国内Android原生自带的com.google.android.gms服务几乎处于不可用状 ...