【题目链接】: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. .NET平台开源JSON库LitJSON的使用方法

    下载地址:LitJson.dll下载 一个简单示例: String str = "{'name':'cyf','id':10,'items':[{'itemid':1001,'itemnam ...

  2. 《生活在Linux中》之:在Bash的Emacs模式中使用Vim

    export EDITOR=vim ctrl-x ctrl-e

  3. Cocos2d-x3.0 RenderTexture(三)

    .h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...

  4. c6----函数的声明和实现

    // // main.c // 函数的声明和定义 // // Created by xiaomage on 15/6/7. // Copyright (c) 2015年 xiaomage. All r ...

  5. 蓝桥杯--算法提高 排列数 (简单dfs)

    算法提高 排列数   时间限制:1.0s   内存限制:256.0MB      问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...

  6. 【BZOJ 2152】 聪聪可可

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2152 [算法] 点分治 [代码] #include<bits/stdc++.h ...

  7. BZOJ 4321 DP

    思路: 这个DP太神了- 完全没想到 http://blog.csdn.net/geotcbrl/article/details/49663401 //By SiriusRen #include &l ...

  8. 弹出ifame页面(jquery.reveal.js)

    <body> <a data-reveal-id="myModalDailyModify" data-animation="fade" tit ...

  9. Hua Wei 机试题目一

    一.身份证号码验证 题目描述: 我国公民的身份证号码特点如下:1. 长度为18位:2. 第1-17位只能为数字:3. 第18位可以是数字或者小写英文字母x.4. 身份证号码的第7~14位表示持有人生日 ...

  10. 有关DevExpress 安装后vs工具箱不显示图标的错误

    在https://www.devexpress.com/Support/Center/Question/Details/T214296/missing-icons-from-toolbox找到解决方法 ...