这几天好懒,昨天写的题,今天才来写博客....

这题你不知道它究竟有多少层,但是知道字符串长度不超过10^6,那么它的总容量是被限定的,用一个二维动态数组就OK了。输入字符串后,可以把它按照逗号分割成一个string数组,然后两个一处理就行,遇到0结束。

AC代码:

#include<cstdio>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
char s[maxn];
string a[maxn];
vector<string>v[maxn/2];
int cur=0,ans,len;
int deal(){
	int u=0;
	for(int i=0;s[i]!='\0';++i){
		if(s[i]==',') continue;
		a[u]="";
		while(s[i]!=','&&s[i]!='\0'){
			a[u]+=s[i++];
		}
		++u;
		--i;
	}
	return u;
}
int gett(string p){
	int c=0;
	for(int i=0;i<p.size();++i)
		c=c*10+(p[i]-'0');
	return c;
}
void dfs(int lev){
	//if(cur>=len) return;
	ans=max(ans,lev);
	v[lev].push_back(a[cur++]);
	int c=gett(a[cur++]);
	for(int i=0;i<c;++i){
		dfs(lev+1);
	}
}
int main(){
	while(scanf("%s",s)!=EOF){
		len=deal();
		cur=0;
		ans=-1;
		for(;cur<len;)
			dfs(0);
		printf("%d\n",ans+1);
		for(int i=0;i<=ans;++i){
			for(int j=0;j<v[i].size();++j)
				if(j==0) cout<<v[i][j];
				else cout<<" "<<v[i][j];
			printf("\n");
		}
		for(int i=0;i<maxn/2;++i) v[i].clear();
	}
	return 0;
}

如有不当之处欢迎指出!

CodeForces-747E的更多相关文章

  1. 【codeforces 747E】Comments

    [题目链接]:http://codeforces.com/problemset/problem/747/E [题意] 给你一个类似递归的结构; 让你把每一层的字符串按照层,一层层地输出出来; 并输出层 ...

  2. CodeForces 747E Comments

    栈,模拟. 手动写一个栈模拟一下过程即可. #include<cstdio> #include<cstring> #include<string> #include ...

  3. Codeforces Round #387 (Div. 2) 747E

    这题本身是个水题,但是写了半天 题意就是给出一个树的生成方式,让你还原这棵树,然后按深度输出结点 这个还原过程还是比较有趣的(没有用递归) PS:getline的新姿势get #include < ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  10. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. java.lang.ClassNotFoundException: com.radiadesign.catalina.session.RedisSessionHandlerValve

    org.apache.tomcat.util.digester.Digester.startElement Begin event threw exception java.lang.ClassNot ...

  2. 深入分析java传参

    概述      java中的参数传递问题可以根据参数的类型大致可以分为三类:传递基本类型,传递String类型,传递引用类型,至于最终是否可以归纳为值传递和引用传递,根据每个人的理解不同,答案不同,此 ...

  3. libev-4.20编译安装及简单使用

    1.源码下载地址: http://www.csdn.net/tag/libev/download 2.库的编译与安装 解压文件,进入文件目录 编译的时候需要首先切换为管理员(root)账户,然后执行以 ...

  4. Codeforces B. Divisiblity of Differences

    B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...

  5. VS工程中的Windows.h

    才发现这个Windows.h是有些奥秘的,不是随便引用就可以的. 1,C++工程,头文件引用要讲求一定顺序.如果cpp文件先引用a.h,再引用b.h,则后者自动包含a.h.这一点很重要. 2,Wind ...

  6. 老凡原创PHPcms发布上架chinaz

    FanCms内容管理系统(3网兼容) FanCms内容管理系统(3网兼容)核心使用CodeIgniter框架.使用SQlite数据库,不需要安装,上传到任意支持PHP的空间,就能使用.高级URL自定义 ...

  7. C#基础(四)--值类型和引用类型,栈和堆的含义

    本文主要是讨论栈和堆的含义,也就是讨论C#的两种类据类型:值类型和引用类型: 虽然我们在.net中的框架类库中,大多是引用类型,但是我们程序员用得最多的还是值类型. 引用类型如:string,Obje ...

  8. apr-util的安装

    下载软件 下载链接: http://pan.baidu.com/s/1o6sOwgM http://pan.baidu.com/s/1hqIdcA4 ########安装apr######### ta ...

  9. iOS-Mac配置Tomcat【Mac环境配置Tomcat】

    Tomcat配置 1.官网下载Tomcat配置包:http://tomcat.apache.org/download-70.cgi 2.下载之后,将解压后的的整个文件夹重新命名:ApacheTomca ...

  10. 解决AspNet Zero Core 5.0.1无法运行的问题

    最近在研究AspNet Zero Core 5.0.1时发现VS点击调试后就自动退出了,从ABP QQ群里得知作者加入了licensecode校验.经过一个周左右断断续续的折腾,算是破解了吧.原本想把 ...