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) 特征 注释本身并不是坏事.但是常常有这样的情况:一段代码中出现长长的注释,而它之所以存在,是因为代码很糟糕. 问题原因 注释的作者意识到自己的代码不直观或不明 ...
随机推荐
- javascript 学习总结(八)属性定义方法
1.defineProperty /* 定义(Definition).定义属性需要使用相应的函数,比如: Object.defineProperty(obj, "prop", pr ...
- 领域模型(Domain Model)
领域模型(Domain Model) 一:面向对象设计中最简单的部分与最难的部分 如果说事务脚本是 面向过程 的,那么领域模型就是 面向对象 的.面向对象的一个很重要的点就是:“把事情交给最适合的类去 ...
- 更新部分字段 NHibernate
更新部分字段 NHibernate 概述: 在有些情况下,我只想更新记录中的一个字段的值.比如:浏览完这条记录后,我把其中的是否浏览置为1. Nhibernate中提供了Native SQL,其中有一 ...
- DropDownList和GridView用法
DropDownList和GridView用法 DropDownList控件和GridView控件在Asp.net中相当常用,以下是控件的解释,有些是常用的,有些是偶尔的,查找.使用.记录,仅此而 ...
- java UDP网路编程
大家都知道java中的socket网络编程,而其采用的协议分别有tcp和udp协议两种. 通常的理解tcp协议类似于打电话,udp类似于发短信.前者是线程安全的,但是效率比较低.后者则刚好相反. 今天 ...
- iOS基础 - 类扩展
一.类扩展(class extension,匿名分类) 1.格式 @interface 类名 () { // 成员变量... } // 方法声明... @end 2.作用 1> 写在.m文件中 ...
- 朴素贝页斯分类法 c++实现
朴素贝叶斯法是基于贝叶斯定理与特征条件独立假设的分类方法.对于搞机器学习的同学们来说,这是相对简单但效果较好的模型. 朴素贝叶斯方法的理论 设输入为n维特征向量X={x1,x2,...,xn},输出为 ...
- Binder机制,从Java到C (3. ServiceManager in Java)
上一篇 Binder机制,从Java到C (2. IPC in System Service :AMS) 中提到 Application是通过ServiceManager找到了AMS 的servic ...
- Oracle 补丁及opatch 工具介绍
一. CPU(Critical Patch Update) 一个CPU内包含了对多个安全漏洞的修复,并且也包括相应必需的非安全漏洞的补丁.CPU是累积型的,只要安装最新发布的CPU即可,其中包括之前发 ...
- 何为分类,UIImageView举例
终于开始自己这个“聚水成洋”的路程了. 经过近一年的iOS学习和开发,遇到很多困难,一开始的陌生和畏惧,中途的困惑和纠结,解决问题后的豁然开朗和总结提升,自己就在这样一个不断的循环中逐渐成长起来了. ...