【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- phpEXCEL如何设置单元格格式为百分比
$objExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_S ...
- SQLSERVER数据库还原的时候,报 WITH MOVE 子句可用于重新定位一个或多个文件 的错误,求解决
http://www.flybi.net/question/4070 梁勇 - 天善智能微软BI首席讲师 数据库备份文件还原产生这个错误的原因是:还原目录下存在多个同名文件, 如图所示,只需要将第2个 ...
- ASP.NET--identity笔记及截图
aspnetUsers aspnetRoles aspnetUserroles aspnetUserClaims 存储用户user额外信息的键值对 aspnetUserLogins 第三方登陆的控件 ...
- [Tailwind] Abstract Utility Classes to BEM Components in Tailwind
When creating UIs with utility classes, a lot of repetition can occur within the HTML markup. In thi ...
- 【手势交互】6. 微动VID
中国 天津 http://www.sharpnow.com/ 微动VID是天津锋时互动科技有限公司开发的中国Leap Motion. 它能够识别并跟踪用户手部的姿态.包含:指尖和掌心的三维空间位置:手 ...
- ubuntu中写一个shell脚本的过程
gedit hello.sh ,然后输入 #!/bin/bash echo "Hello world!" chmod +x hello.sh ./hello.sh
- java 抽象类和接口的差别
语法层面上: 1)抽象类能够提供成员方法的实现细节.而接口中仅仅能存在public abstract 方法. 2)抽象类中的成员变量能够是各种类型的.而接口中的成员变量仅仅能是public st ...
- 【java项目实战】dom4j解析xml文件,连接Oracle数据库
简单介绍 dom4j是由dom4j.org出品的一个开源XML解析包.这句话太官方.我们还是看一下官方给出的解释.例如以下图: dom4j是一个易于使用的.开源的,用于解析XML,XPath和XSLT ...
- mysql改动用户password
登录root用户 用root用户登录控制台. use mysql use mysql,mysql是mysql数据库自己主动创建的一个数据库. 改动user表的数据 update user set pa ...
- Codeforces 456B Fedya and Maths 打表找规律
Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expre ...