poj1068
来源:互联网 发布:加拿大木结构设计软件 编辑:程序博客网 时间:2024/05/22 02:01
#include <iostream>#include <stdio.h>using namespace std;int main(){ int n,m,i,j,k,t,z,x; char p[1000000]; //freopen("in.txt","r",stdin); cin>>n; for (i=1;i<=n;i++) { cin>>m; //还原括号串 t=0;z=0; // t表示左括号总数,z为指针 for (j=1;j<=m;j++) { cin>>k; while (t<k) { z++; t++; p[z]='1'; //1表示左括号 } z++; p[z]='0'; //0表示右括号 } //for (j=1;j<=z;j++) cout<<p[j];cout<<endl; for (j=1;j<=z;j++) if (p[j]=='0') { t=0;x=j; do { x--; if (p[x]=='2') t++; //有一个右括号及包含一对括号,并做标记 }while (p[x]!='1'); cout<<t+1<<" "; p[x]='2'; } cout<<endl; } return 0;}
题意:一个括号表达式可以按照如下的规则表示,就是每个右括号之前的左括号数。比如(((()()()))),每个右括号之前的左括号数序列为P=4 5 6 6 6 6,而每个右括号所在的括号内包含的括号数为W=1 1 1 4 5 6.现在给定P,输出W。
0 0
- POJ1068
- POJ1068
- Poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- 算法第9题
- p122第15题
- DNS BIND主辅同步部署
- 2015/4/18(2)
- 再读 K-Means
- poj1068
- HTML编码规范
- 向WCF服务提交Stream类型的数据
- Scala学习笔记
- Oracle数据库PL/SQL学习笔记——函数定义
- 安卓开发中用volley框架请时,中文返回乱码问题
- VI中的多行删除与复制 [转载]
- 想听懂用户的声音,至少得先学会数据分析吧
- 数学逻辑