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) 特征 注释本身并不是坏事.但是常常有这样的情况:一段代码中出现长长的注释,而它之所以存在,是因为代码很糟糕. 问题原因 注释的作者意识到自己的代码不直观或不明 ...
随机推荐
- C# & WPF 随手小记之一 ——初探async await 实现多线程处理
嗯...我也是在园子待了不短时间的人了,一直以来汲取着园友的知识,感觉需要回馈什么. 于是以后有空我都会把一些小技巧小知识写下来,有时候可能会很短甚至很简单,但希望能帮到大家咯. 第一篇文章来说说as ...
- leetcode第30题--Next Permutation
problem: Implement next permutation, which rearranges numbers into the lexicographically next greate ...
- SQL SERVER存储过程生成字母+数字的编码
公司内设备管理系统中设备建账功能,功能目的是对新进设备进行记录并入库.其中设备编号一项定义为自己修改(查看之前的设备号,取一个不重复的值来填写),感觉特别麻烦!用存储过程自动生成编码岂不是更效率. 需 ...
- Java凝视Override、Deprecated、SuppressWarnings详细解释
一.什么是视线 说起目光,你必须先提什么是元数据(metadata). 所谓元数据是数据的数据.那.元数据是描述数据的叙述. 像在表中的数据字段,叙述了这个字段下的数据的含义.而J2SE5.0 ...
- 【转】Android学习系列–App离线下载功能实现
原文:http://www.cnblogs.com/qianxudetianxia/archive/2011/07/20/2108965.html 宜未雨而绸缪,毋临渴而掘井.----朱用纯<治 ...
- 转载:21个免费的UI界面设计工具、资源及网站
我们刚刚介绍了移动设计初探:触屏网页设计.本文将介绍一些UI界面与设计使用的元素.软件和网站.内容很丰富,适合用户体验设计师.界面设计师.产品设计师.JS前段开发.手机产品设计以及iPad和平板电脑产 ...
- 配置serv-u access数据库遇到的一些问题
配置好access数据库后,需要建个web页面来供用户修改密码,但修改时,提示:odbc被占用无法打开. serv-u一直在保持打开access数据库.我们需要将数据库设置默认打开方式为共享,不锁定. ...
- parent和top
function show(){ //parent是获取本窗口的父窗口 //window.parent.location.href="http://www.baidu.com" ...
- Web API中使用Dependency Resolver
Web API中使用Dependency Resolver 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyo ...
- IT职位分析
人才市场的IT职位分析 最近要找长沙的工作,于是通过湖南人才市场搜索了一下职位.结果得到的数据让我很难比较,作为一个 IT 业滚爬了多年的程序员,对这样的搜索结果很不满意.于是,我不得不自己来整理 ...