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

这题你不知道它究竟有多少层,但是知道字符串长度不超过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. Hibernate (二)

    1 一级缓存的引入 示例: @Test public void testUpdate(){ Configuration configuration = new Configuration().conf ...

  2. 05_Javascript进阶第二天

    String对象 res=str.charAt(1);//返回字符串中第n个字符(输出:i) res=str.charCodeAt(1);//返回第n个字符的ASCII编码(输出:105) res=S ...

  3. PHP date函数详解

    在页面的最前页加上date_default_timezone_set(PRC);   /*把时间调到北京时间,php5默认为格林威治标准时间*/date ()a:   "am"或是 ...

  4. php的print_r第二个参数是true有啥用啊

    print_r(); 第二个参数 为true时 返回值 而不显示. echo ,print,print_r的区别 echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量 ...

  5. ng机器学习视频笔记(一)——线性回归、代价函数、梯度下降基础

    ng机器学习视频笔记(一) --线性回归.代价函数.梯度下降基础 (转载请附上本文链接--linhxx) 一.线性回归 线性回归是监督学习中的重要算法,其主要目的在于用一个函数表示一组数据,其中横轴是 ...

  6. linux 搭建PPTP

    pptp简介 PPTP,Point to Point Tunneling Protocol,点对点隧道协议,这是一种支持多协议虚拟专用网络(VPN)技术.远程用户能够通过装有点对点协议的系统安全访问公 ...

  7. CentOS安装scp命令

    scp这东西应该属于openssh-clients这个包,运行: yum -y install openssh-clients 再运行scp就可以了,再次运行: .txt 注意,scp 命令操作的两端 ...

  8. iOS-FMDB事务【批量更新数据】

    打开数据库(sqlite) ///打开数据库 + (BOOL)openDataBase{ _TYDatabase = [[FMDatabase alloc]initWithPath:[self dat ...

  9. 玩转spring boot——国际化

    前言 在项目开发中,可能遇到国际化的问题,而支持国际化却是一件很头疼的事.但spring boot给出了一个非常理想和方便的方案. 一.准备工作 pom.xml: <?xml version=& ...

  10. JMS基础篇

    首先我们需要下载 ActiveMQ:http://activemq.apache.org/. 启动 ActiveMQ 服务:解包下载的 ActiveMQ >进去其bin 目录>双击 act ...