栈,模拟。

手动写一个栈模拟一下过程即可。

#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的更多相关文章

  1. 【codeforces 747E】Comments

    [题目链接]:http://codeforces.com/problemset/problem/747/E [题意] 给你一个类似递归的结构; 让你把每一层的字符串按照层,一层层地输出出来; 并输出层 ...

  2. Codeforces Round #387 (Div. 2) 747E

    这题本身是个水题,但是写了半天 题意就是给出一个树的生成方式,让你还原这棵树,然后按深度输出结点 这个还原过程还是比较有趣的(没有用递归) PS:getline的新姿势get #include < ...

  3. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

  4. Codeforces Round #459 (Div. 2):B. Radio Station

    B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...

  5. 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 ...

  6. Codeforces Round #459 (Div. 2)

    A. Eleven time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  7. Codeforces Round #564 (Div. 2)A

    A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...

  8. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  9. 代码的坏味道(13)——过多的注释(Comments)

    坏味道--过多的注释(Comments) 特征 注释本身并不是坏事.但是常常有这样的情况:一段代码中出现长长的注释,而它之所以存在,是因为代码很糟糕. 问题原因 注释的作者意识到自己的代码不直观或不明 ...

随机推荐

  1. 探秘IntelliJ IDEA 13测试版新功能——调试器显示本地变量

    IntelliJ IDEA在业界被公认为最好的Java开发平台之一,JetBrains公司将在12月正式发布IntelliJ IDEA 13版本. 现在,小编将和大家一起探秘密IntelliJ IDE ...

  2. html5 图片上传版本1.0

    1.代码如下: /* autor:shzihouyu date:2015-12-11 ver:1.0 */ var szyFile = { fileDom:null,//html 文件上传控件 pre ...

  3. Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式

    Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式 作者:ch ...

  4. C#/ASP.NET/AJAX

      C#/ASP.NET/AJAX ASP.NET 4.5新特性一:强类型数据绑定(Strongly-Type Data-Bindings) 摘要: 随着ASP.NET 4.5的发布提供了很多的新特性 ...

  5. ofbiz学习笔记01--多表关联查询

    不管做什么项目,肯定会用到多表关联查询数据,从网络查询得知ofbiz有三种多表关联查询方法 实现一:Screem.xml 中的 section 里,加 <action>, 加 get-re ...

  6. location的使用

    <script language="javascript" type="text/javascript"> function setUrl(){   ...

  7. The Decoder - UVa458

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva458.html 题目描述  The ...

  8. NotePad++安装和配置C/C++开发插件

    NotePad++ - 安装和配置C/C++开发插件 | NotePad++ - Install and Configure plugins for develop C/C++ http://aofe ...

  9. (翻译) Android ListView 性能优化指南

    本文翻译了Lucas Rocha的Performance Tips for Android’s ListView.这是一篇关于介绍如何提升ListView性能的文章,非常的优秀.使得我拜读之后,忍不住 ...

  10. JDBC之事务隔离级别以及ACID特性

    JDBC之事务隔离级别以及ACID特性 事务隔离级别: 1.更新遗失(Lost update) 两个事务都同时更新一行数据,但是第二个事务却中途失败退出,导致对数据的两个修改都失效了.这是因为系统没有 ...