CodeForces 747E Comments
栈,模拟。
手动写一个栈模拟一下过程即可。
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<iostream>
using namespace std; char t[];
struct X
{
string name;
int son;
}s[]; char tmp[];
int cnt;
int num; vector<string> ans[]; stack<int>k; int max_dep,now_dep;
int len,p=-,sz; bool wu()
{
if(p==len-) return ;
return ;
} void add()
{
p++; cnt=;
while()
{
if(t[p]==',') break;
tmp[cnt++] = t[p++];
}
tmp[cnt]=; p++; num=;
while()
{
if(t[p]==',') break;
num=num*+t[p]-'';
p++;
} s[sz].name = tmp;
s[sz].son = num;
sz++;
} void Push(int x)
{
if(k.empty()) k.push(x);
else
{
int Top=k.top();
s[Top].son--;
k.push(x);
}
now_dep++;
max_dep = max(max_dep,now_dep);
ans[now_dep].push_back(s[x].name);
} void Pop()
{
while()
{
if(k.empty()) break;
int Top=k.top();
if(s[Top].son==)
{
now_dep--;
k.pop();
}
else break;
}
} int main()
{
scanf("%s",t); len=strlen(t);
t[len]=','; len++; t[len]=; while()
{
if(wu()) break;
add();
Push(sz-);
Pop();
} cout<<max_dep<<endl;
for(int i=;i<=max_dep;i++)
{
for(int j=;j<ans[i].size();j++)
{
cout<<ans[i][j]<<" ";
}
cout<<endl;
} return ;
}
CodeForces 747E Comments的更多相关文章
- 【codeforces 747E】Comments
[题目链接]:http://codeforces.com/problemset/problem/747/E [题意] 给你一个类似递归的结构; 让你把每一层的字符串按照层,一层层地输出出来; 并输出层 ...
- Codeforces Round #387 (Div. 2) 747E
这题本身是个水题,但是写了半天 题意就是给出一个树的生成方式,让你还原这棵树,然后按深度输出结点 这个还原过程还是比较有趣的(没有用递归) PS:getline的新姿势get #include < ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- Codeforces Round #459 (Div. 2):B. Radio Station
B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...
- Codeforces Round #564 (Div. 2) A. Nauuo and Votes
链接:https://codeforces.com/contest/1173/problem/A 题意: Nauuo is a girl who loves writing comments. One ...
- Codeforces Round #459 (Div. 2)
A. Eleven time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #564 (Div. 2)A
A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- 代码的坏味道(13)——过多的注释(Comments)
坏味道--过多的注释(Comments) 特征 注释本身并不是坏事.但是常常有这样的情况:一段代码中出现长长的注释,而它之所以存在,是因为代码很糟糕. 问题原因 注释的作者意识到自己的代码不直观或不明 ...
随机推荐
- POJ 1579-Function Run Fun(内存搜索)
Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16503 Accepted: 8514 ...
- 使用rem设计移动端自适应页面二(转载)
由于日常需求以无线居多,所以可以在业务中做一些尝试,如 rem,刚接触这个特性的时候,曾经一度爱不释手,仿佛在无线开发的坎坷路上寻找到一条捷径.然而随着使用范围的扩大,慢慢的发现了一些使用 rem 带 ...
- 在希望的田野上--生物柴油(Biodiesel)光明的未来
请看下图: 这是科学家Bernie Tao教授给美国Purdue大学的学生们出的题目"有关大豆.谷物产品的创新竞赛",实质上,就是鼓舞研究.开发及应用生物柴油(Biodiesel) ...
- Value Object(值对象)如何使用 EF 进行正确映射
DDD 领域驱动设计-Value Object(值对象)如何使用 EF 进行正确映射 写在前面 首先,这篇博文是用博客园新发布的 MarkDown编辑器 编写的,这也是我第一次使用,语法也不是很熟悉, ...
- gulp package.json
{ "name": "gulpAngular1", "version": "0.0.0", "dependen ...
- [转]C# and the using Statement in 3 seconds and a bug in Reflector
Using() Statement in 3 seconds and a bug in Reflector The boring, known accross the board definition ...
- ASP.NET MVC 缓存扩展 - Donut Caching
项目介绍 ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code ...
- IDE编程环境
Vim配置及说明——IDE编程环境 目录 Vim配置及说明——IDE编程环境 1.基本及字体 2.插件管理 3.主题风格 4.窗口设置 5.目录树导航 6.标签导航 7.taglist 8.多文档编辑 ...
- Asp.net MVC4.0(net4.5) 部署到window server 2003上的解决方案
Asp.net MVC4.0(net4.5) 部署到window server 2003上的解决方案 最近做了一个Web项目,也没多想就用了Asp.net MVC4.0 ,MVC4.0默认的目标fra ...
- springmvc的一些记录
1.springmvc基本配置 2.springmvc+hibernate4配置 3.springmvc+hibernate4+freemarker配置 4.springmvc+hibernate4+ ...