【题目链接】:http://codeforces.com/problemset/problem/747/E

【题意】



给你一个类似递归的结构;

让你把每一层的字符串按照层,一层层地输出出来;

并输出层数;

【题解】



递归里面,写:

当前层开始的位置,这一层里面有多少个字符串,以及层的深度;

每次搞到下一层最右的下标就好;

然后每找到一个字符就加入到这一层里面;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e6 + 100; string temp;
char s[N];
int len, ma;
vector <string> ans[N]; void dfs(int i, int should, int dep)
{
int j = i, num = 0;
while (1)
{
if (j>len) return;
temp = "";
while (j <= len && s[j] != ',')
{
temp += s[j];
j++;
}
ans[dep].pb(temp);
LL temp1 = 0;
j++;
while (j <= len && s[j] != ',')
{
temp1 = temp1 * 10 + s[j] - '0';
j++;
}
ma = max(ma, j + 1);
if (temp1 == 0)
{
j++;
}
else
{
ma = j + 1;
dfs(j + 1, temp1, dep + 1);
j = ma;
}
num++;
if (num == should) return;
} }
int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> (s + 1);
len = strlen(s + 1);
dfs(1, len, 1);
int dep = 1;
while (int(ans[dep + 1].size())) dep++;
cout << dep << endl;
rep1(i, 1, dep)
{
int len = ans[i].size();
rep1(j, 0, len - 1)
{
cout << ans[i][j];
if (j == len - 1)
cout << endl;
else
cout << ' ';
}
}
return 0;
}

【codeforces 747E】Comments的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. nodejs-app.js

    设置静态目录 1 2 app.use(express.static(path.join(__dirname, 'public'))); //设置模版渲染的js,css,images的静态文件目录 设置 ...

  2. spring datasource和mybatis的datasource来源在哪里

    配置一个数据源     spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源.  配置一个 ...

  3. [MongoDB实战]Part1 起步

    本书的这部分对MongoDB进行了一个大致的简介.包括了Javascript Shell和Ruby驱动,这俩都有例子 在第一章,我们将了解到MongoDB的历史,设计目的和实际使用的场景.我们还将了解 ...

  4. bash脚本编程知识储备

    bash脚本编程:     脚本程序:解释器解释执行: 首先得理清一些琐碎的知识点,我尽量把我所学的帮朋友一起梳理一下 编程环境:(我会在接下来的篇章,图文例子三结合的方式带大家一起学习)       ...

  5. 关于App class loader的总结

    关于App class loader的总结 2010-05-11 15:19:09 分类: 系统运维 Java本身是一种设计的非常简单,非常精巧的语言,所以Java背后的原理也很简单,归结起来就是两点 ...

  6. emacs使用本地emacs server模式打开远程文件

    使用emacs的用户都知道,一般要打开远程机器上的文件要使用TrampMode模式,调用方式例如以下: C-x C-f /remotehost:filename RET (or /method:use ...

  7. 自醒的觉悟与力量——leo鉴书59

    30岁之后由于看得书多起来,阅读和写作也都有了自己的套路,与此相对的写书评之前须要看几遍书,然后我才干下笔的作者和作品越来越少了. 崔卫平是这种作者,而<正义之前>是我看了两遍才開始写评的 ...

  8. .NET开源的背后:是无奈,还是顺应潮流?

    摘要:微软.NET的开源,让很多开发者欣喜若狂.同一时候也有很多人好奇其背后的故事,过去视开源为癌症的微软为什么会突然有这一举措,是出于无奈,还是顺应潮流,而这当中的种种也许能够用文中的六个观点来说明 ...

  9. C/C++ 工具函数 —— 大端模式和小端模式的互换

    小端模式:小在小,大在大:大端模式:小在大,大在小: uint32_t swap_endian(uint32_t val) { val = ((val << 8) & 0xFF00 ...

  10. Caffe solver.prototxt学习

    在solver解决下面的四个问题: a.训练的记录(bookkeeping),创建用于training以及test的网络结构: b.使用前向以及反向过程对training网络参数学习的过程: c.对t ...