Your task is to simulate a flood damage.

For a given cross-section diagram, reports areas of flooded sections.

Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.

Input

A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\".

output

Report the areas of floods in the following format:

A
k L1 L2 ... Lk

In the first line, print the total area A of created floods.

In the second line, print the number of floods kk and areas Li(i=1,2,...,k) for each flood from the left side of the cross-section diagram. Print a space character before Li.

Constraints

  • 1≤ length of the string ≤20,000

Sample Input 1

\\//

Sample Output 1

4
1 4

Sample Input 2

\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\

Sample Output 2

35
5 4 2 1 19 9 附上AC代码,至于在解这道题的过程中遇到的许多问题,在代码中都写有注释:

#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
const int maxn=2e4+10;
// 本来不想用结构体,对于这种两个绑定的,可以用pair,可是用pair之后发现程序运行的很不成功,以为是pair用错了语法,
// 毕竟c++我暂时是自学,pair也是只要从网上看的,于是就把pair改为了结构体,结果运行仍是很不成功,改了很久才发现真正的问题,
struct node //最后才知道pair没有用错,不过都写成结构体了,也就不再改为pair了
{
int first,second;
};
stack<struct node >s; //存储面积信息,位于字符串的第i位开始的'\',以其为最左边的拦截面积,存储的是,(i,si)
stack<int>q; //存储第几位是'\\'
char str[maxn]; //存储输入的三种字符
int main()
{
int i,j,sum=0;
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]=='\\') q.push(i);
if(str[i]=='/')
{
if(!q.empty())
{
struct node s1;
s1.second=i-q.top();
sum+=s1.second;
s1.first=q.top();
q.pop();
if(!s.empty()) //之前没有判断这一步,包括下面的是否为空的判断也没有,就导致在第一次引用时,栈s肯定是空,但是我用了s.top(),所以会出错
{
while(1)
{ //这里是关键,判断能不能合并成一个拦截面积
if(!s.empty()&&s1.first<s.top().first) s1.second+=s.top().second,s.pop(); /* 在这里遇到了最后一个问题,我原先写的是
if(s1.first<s.top().first&&!s.empty())但是这么写仍旧程序运行不成功,然后检查bug时看到这里想起了以前看到过的if条件的判断,如果是||连接的,则从左到右判断,
若发现存在正确的条件之一时会直接显示正确,并且之后的条件不再进行检查,而&&则是如果遇见错误的条件之一时,直接判断为false,并且不再检查之后的条件,
如果按照我原先写的,当栈为空时,我却调用了top(),便会理所当然的出现与之前说的同一个问题,但是如果改为我现在写的AC的代码,先判断是不是空,如果是空,
则直接为false,并且不再进行之后的条件判断,便不会出现当栈为空时,仍掉用栈顶元素的现象 */
else {s.push(s1);break;}
}
}
else s.push(s1);
}
else continue;
}
}
int k=s.size();
printf("%d\n%d",sum,k);
int su[maxn];
for(int i=0;i<k;i++) //本来想用队列这种结构了,队列在这里的输出非常简单,可是不能调用队尾元素了(可能可以调用,但是我没遇见过),之前的代码就不能运行,所以就有改为了栈
su[i]=s.top().second,s.pop();
for(int i=k-1;i>=0;i--)
printf(" %d",su[i]);
cout<<endl; //本来没有这句话竟然显示PE,可是一直不明白为什么会有这句话,在题面中也没有写啊,最后还是凭借感觉写上了这句话,然后就AC了
return 0;
}

												

最新文章

  1. Java_动态编译总结
  2. 如何做到在虚拟数据库和真实数据库之间自由切换?【低调赠送:QQ高仿版GG 4.4 最新源码】
  3. 54. 八皇后问题[eight queens puzzle]
  4. easyui datagrid的列编辑
  5. 如何设置BIOS使服务器断电后再来电能自动开机
  6. contact表单错误解决记录
  7. weblogic漏洞修复:CVE-2014-4210,UDDI Explorer对外开放
  8. TCP协议的滑动窗口协议以及流量控制
  9. python基础-------函数(一)
  10. Smarty3.1.3安装使用
  11. 织梦cms网上复制图片不可用的解决方法
  12. APP中一种在Java层实现的简单守护进程方式
  13. 闽江学院软件学院2016级JAVA构建之法-学生自学兴趣小组招募通知
  14. myBase7 激活方法
  15. L245
  16. easyui学习笔记14-拓展的基本验证规则
  17. 2013337朱荟潼 Linux第四章读书笔记——进程调度
  18. _STORAGE_WRITE_ERROR_
  19. linux网络流量实时监控工具之iptraf 【个人比较喜欢用的流量监控软件】
  20. shell输入与输出功能

热门文章

  1. C#将MD5后的字符串转为字符数据,随机大小写
  2. Rsync+sersync部署
  3. 【转】C/C++产生随机数
  4. Mac sublime 安装包的时候出现 unable to download xxx (_ssl.c:548)
  5. rabbitmq tags
  6. Python---基础---常用的内置模块
  7. JavaWeb(四):JDBC
  8. How To Create/Extend Swap Partition In Linux Using LVM
  9. php substr()函数 语法
  10. java文件断点上传