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) 特征 注释本身并不是坏事.但是常常有这样的情况:一段代码中出现长长的注释,而它之所以存在,是因为代码很糟糕. 问题原因 注释的作者意识到自己的代码不直观或不明 ...
随机推荐
- Asterisk 未来之路3.0_0003
原文:Asterisk 未来之路3.0_0003 Asterisk: The Hacker's PBX 如果电信公司忽视了asterisk,那么正在处于危险中.asterisk 良好的扩展性,能够创建 ...
- SSMS2008插件开发(2)--Microsoft Visual Studio 2008插件开发介绍
原文:SSMS2008插件开发(2)--Microsoft Visual Studio 2008插件开发介绍 由于开发SSMS2008插件是通过VS2008进行的,有必要先介绍一下VS2008的插件开 ...
- 基于EF+WCF的通用三层架构及解析
分享基于EF+WCF的通用三层架构及解析 本项目结合EF 4.3及WCF实现了经典三层架构,各层面向接口,WCF实现SOA,Repository封装调用,在此基础上实现了WCFContext,动态服务 ...
- HTML表单元素
HTML表单元素 表单元素同意的形式向用户(例:文本字段,下拉列表,单箱,检查盒等)输入元素信息 表单标签 文本域(Text Fields) 当用户要在表单中键入字母,数字等内容时,就会用到文本域 单 ...
- Oracle中的Union、Union All、Intersect、Minus
Oracle中的Union.Union All.Intersect.Minus 众所周知的几个结果集集合操作命令,今天详细地测试了一下,发现一些问题,记录备考. 假设我们有一个表Student,包括 ...
- C#/ASP.NET/AJAX
C#/ASP.NET/AJAX ASP.NET 4.5新特性一:强类型数据绑定(Strongly-Type Data-Bindings) 摘要: 随着ASP.NET 4.5的发布提供了很多的新特性 ...
- Varnish缓存服务
Varnish缓存服务详解及应用实现 1.varnish的基本介绍 Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已 ...
- MVC5入门学习系列④
添加Model且简单的使用EF 对于EF(EntityFramework)不了解的朋友可以去百度文科或者在园子里搜一些简资源看下,假如和我一样知道EF的概念,那么就知道EF有一个code first的 ...
- SpringMVC Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
SpringMVC学习系列(12) 完结篇 之 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现 到这里已经写到第12篇了,前11篇基本上把Spring M ...
- POJ 3667 & 1823 Hotel (线段树区间合并)
两个题目都是用同一个模板,询问最长的连续未覆盖的区间 . lazy代表是否有人,msum代表区间内最大的连续长度,lsum是从左结点往右的连续长度,rsum是从右结点往左的连续长度. 区间合并很恶心啊 ...