【codeforces 747E】Comments
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- 跳一跳的Python环境搭建
微信最新的小程序里面出了个叫“跳一跳”的小游戏,一经推出立马刷爆了朋友圈,而一些大神们也通过Python实现了自动玩游戏具体代码见(Github地址:https://github.com/wangsh ...
- LightOJ1214 Large Division
/* LightOJ1214 Large Division http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1 ...
- Java 零基础跑起第一个程序
Java 零基础跑起第一个程序 一 概述 1 java代码编译 编译后才干在计算机中执行.编译就是把人能看懂的代码转换成机器能看懂的形式 2 java的长处 一次编译.到处执行.由于java代码是在 ...
- ubuntu16.04安装配置mysql数据库,分割视频为帧图像
参考http://wiki.ubuntu.org.cn/MySQL%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97 版本为5.7 一.安装 安装命令sudo apt-get i ...
- chrome设置书签默认显示
实用的设置! 这样已设置,就可以方便的查看一些常用的书签了!
- 英语发音规则---X字母
英语发音规则---X字母 一.总结 一句话总结: 1.x位于词尾或音节尾部,读/ks/? box /bɒks/ n.盒; 箱状物 fix /fɪks/ vt.固定 fox /fɒks/ n.狐; 狐狸 ...
- numpy的scale就是 x-mean/std
>>> from sklearn import preprocessing >>> import numpy as np >>> a=np.arr ...
- 蓝桥杯--算法提高 排列数 (简单dfs)
算法提高 排列数 时间限制:1.0s 内存限制:256.0MB 问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...
- python面向对象与结构成员之间的关系
1面向对象结构分析:----面向对象整体大致分为两块区域:-------第一部分:静态字段(静态变量)部分-------第二部分:方法部分--每个区块可以分为多个小部分 class A: countr ...
- Redis学习笔记(五) 基本命令:Hash操作
原文链接:http://doc.redisfans.com/hash/index.html 学习前先明确一下概念,这里我们把Redis的key称作key(键),把数据结构hash中的key称为fiel ...