Parencodings(imitate)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 20679 | Accepted: 12436 |
Description
Following is an example of the above encodings:
S (((()()())))
P-sequence 4 5 6666
W-sequence 1 1 1456
Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string.
Input
Output
Sample Input
2
6
4 5 6 6 6 6
9
4 6 6 6 6 8 9 9 9
Sample Output
1 1 1 4 5 6
1 1 2 4 5 1 1 3 9
Source
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int p[] , w[] ;
int n ;
char s[] ; void convert1 ()
{
int k = ;
for (int i = ; i < p[] ; i++)
s[k++] = '(' ;
s[k++] = ')' ;
for (int i = ; i < n ; i++) {
for (int j = ; j < p[i] - p[i - ]; j++) {
s[k++] = '(' ;
}
s[k++] = ')' ;
}
s[k] = '\0' ;
// puts (s) ;
}
void convert2 ()
{
int l , r ;
int k = ;
for (int i = ; s[i] != '\0' ; i++) {
if (s[i] == ')') {
l = ;
r = ;
for (int j = i - ; j >= ; j--) {
if (s[j] == ')' )
r++ ;
else
l++ ;
if (l == r)
break ;
}
w[k++] = r;
}
}
for (int i = ; i < n ; i++) {
printf ("%d" , w[i]) ;
if (i != n - )
printf (" ") ;
}
puts ("") ;
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int T ;
scanf ("%d" , &T) ;
while (T--) {
scanf ("%d" , &n) ;
for (int i = ; i < n ; i++)
scanf ("%d" , &p[i]) ;
convert1 () ;
convert2 () ;
}
}
Parencodings(imitate)的更多相关文章
- [POJ1068]Parencodings
[POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be enco ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22757 Accepted: 13337 De ...
- hdu 1361 Parencodings 简单模拟
Parencodings 题意: 由括号序列S可经P规则和W规则变形为P序列和W序列. p规则是:pi是第i个右括号左边的左括号的数: w规则是:wi是第i右括号与它匹配的左括号之间右括号的数(其中包 ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
- Poj OpenJudge 1068 Parencodings
1.Link: http://poj.org/problem?id=1068 http://bailian.openjudge.cn/practice/1068 2.Content: Parencod ...
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...
- PO1068 Parencodings 模拟题
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28860 Accepted: 16997 De ...
- Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏
Parencodings Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- SQL 语句大全
转载:http://www.cnblogs.com/yubinfeng/archive/2010/11/02/1867386.html 经典SQL语句大全 一.基础 1.说明:创建数据库 CREATE ...
- storm基础框架分析
背景 前期收到的问题: 1.在Topology中我们可以指定spout.bolt的并行度,在提交Topology时Storm如何将spout.bolt自动发布到每个服务器并且控制服务的CPU.磁盘等资 ...
- 教你用netstat-实践案例
netstat命令的功能是显示网络连接.路由表和网络接口信息,可以让用户得知目前都有哪些网络连接正在运作. 该命令的一般格式为: netstat [选项] 命令中各选项的含义如下: -a 显示所有so ...
- WCF入门(12)
前言 上次写是小半年前的事情了,还在原来的公司,还在原来的项目,同时认识了不少人.外包公司总是有些不适应的地方,总在很闲和很忙之间徘徊.凌晨2点被客户电话叫醒,只为copy一个文件从一台服务器到另一台 ...
- ThreadLocal模式的核心元素
首先来看ThreadLocal模式的实现机理:在JDK的早期版本中,提供了一种解决多线程并发问题的方案:java.lang.ThreadLocal类.ThreadLocal类在维护变量时,世纪使用了当 ...
- c#批量插入示例
var sql = @"Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20131029153010;I ...
- Daily Scrum – 1/15
Meeting Minutes 确定了user course 的方案. 完成了屏幕的自适应: 安排了最后几天的日程 Burndown Progress part 组员 今日工作 Time ...
- Git的基本使用方法和安装&心得体会
1. git的安装和github的注册.代码托管.创建organization.邀请member. (1)git的安装 因为我电脑是windows系统,所以下载的是git for windows.在官 ...
- [转]ORACLE 中ROWNUM用法总结!
原文地址:http://www.itpub.net/thread-824147-1-1.html 对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between ...
- 读JS高级API笔记_(DOM&&DOM2&&DOM3)哎呀——园龄才9个月啊
---恢复内容开始--- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...