poj1068
来源:互联网 发布:苹果电脑音乐制作软件 编辑:程序博客网 时间:2024/05/22 09:06
这题分类在模拟题。。可能是我太水了。。觉得还是没有想象模拟题那么水。。需要动下脑筋。。。
题意:给你两种规则对同一串()的编码,先给你第一种按照第一个)左边有多少个(的个数的编码,你输出第一个)和它往左对应(中间有多少个()的个数的编码。
我的方法是,先按照第一个规则,模拟出这个()串,再按照第二个规则扫一遍,模拟嘛。。就是这么直接嘛(肯定有更简单的)。
还是犯了数组开小,wrong了几次的毛病。
#include<cstdio>#include<cstring>char s[100],w[100];int main(){ int t; scanf("%d",&t); while(t--) { int n,a,t=0; scanf("%d",&n); memset(s,'(',sizeof(s)); for(int i=0;i<n;i++)y { scanf("%d",&a); s[a+t]=')'; t++; } int book[100]={0}; int num=0; for(int i=0;i<n*2;i++) { if(s[i]==')') { for(int j=i;j>=0;j--) { if(s[j]=='('&&book[j]==0) { book[j]=1; w[num++]=(i-j)/2+1; break; } } } } for(int i=0;i<n;i++) printf("%d ",w[i]); printf("\n"); }}
0 0
- POJ1068
- POJ1068
- Poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- WPF 之Triggers
- Android---50---使用Socket进行通信
- Activiti介绍
- 第13周项目1动物这样叫(抽象类)
- Storm高级原语(一) — Transactional topology
- poj1068
- mysql不能远程登录
- mfc怎么把编辑框内的输入的数字存入int 2,如何把数字输出到编辑框内
- jQuery on()方法
- 第十五章输入/输出2015-05-29
- 字符类型之间的转换
- oracle体系结构
- 第六章 树
- 继承