【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- SSM知识巩固2
数据回显 1.springmvc默认对pojo数据进行回显. pojo数据传入controller方法后,springmvc自动将pojo数据放到request域,key等于pojo类型(首字母小写) ...
- C#中的LINQ 基础
1.LINQ的数据源 必须可枚举的,即必须是数组或者集合 (继承了IEnumerable<T>接口就可以,注意是IEnumerable<T>,不是IEnumerable接口,不 ...
- Linux 网卡驱动学习(六)(应用层、tcp 层、ip 层、设备层和驱动层作用解析)
本文将介绍网络连接建立的过程.收发包流程,以及当中应用层.tcp层.ip层.设备层和驱动层各层发挥的作用. 1.应用层 对于使用socket进行网络连接的server端程序.我们会先调用socket函 ...
- bzoj3715: [PA2014]Lustra(乱搞)
3715: [PA2014]Lustra 题目:传送门 题解: 随手一发水题x1 随便排序一下...小学生题??? 代码: #include<cstdio> #include<cst ...
- DatabaseMetaData开发实务
1.总论 在企业开发实务中,数据迁移是经常会遇到的事情,此时,需要搞清楚,源数据库与目的数据库之间表以及表内部各列之间的异同.而有些时候,我们拿到的项目文 档,未必能准确表述各个表的准确结构,即使应用 ...
- [十二省联考2019] 异或粽子 解题报告 (可持久化Trie+堆)
interlinkage: https://www.luogu.org/problemnew/show/P5283 description: solution: 显然有$O(n^2)$的做法,前缀和优 ...
- 原生js实现复选框
简单排版 <style> .box { display: flex; align-items: center; } #allSelect, p { width: 20px; height: ...
- 绘图中的drawRect
rect参数:代表的是当前view的bounds 1 为什么要在drawRect方法里面写绘图代码 因为只有在这个方法中才能获取到当前view相关的图形上下文对象 有了这个图形上写文对象后才能进行绘图 ...
- ROS-导航功能-RVIZ
前言:slam使用激光雷达完成了地图构建,现在介绍一下自主导航.move_base用于实现最优路径规划,amcl用于实现机器人定位. 前提:已下载并编译了相关功能包集,如还未下载,可通过git下载:h ...
- Java 系列之Filter(一)
一.过滤器 过滤器就是在源数据和目的数据之间起过滤作用的中间组件.它可以截取客户端和资源之间的请求和响应信息,并且对这些信息进行过滤. 二.应用场景 1.对用户请求进行统一认证 2.对用户的访问请求进 ...