📄 problem 1016.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://acm.zju.edu.cn/show_problem.php?pid=1016 -->
<HTML><HEAD><TITLE>Problem 1016</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3157" name=GENERATOR></HEAD>
<BODY>
<CENTER><IMG src="Problem 1016.files/logo.gif" align=center></IMG></CENTER>
<HR>
<CENTER><FONT color=blue size=+2>Parencodings</FONT></CENTER>
<HR>
<CENTER><FONT color=green>Time limit:</FONT> 1 Seconds <FONT
color=green>Memory limit: </FONT>32768K </FONT><BR><FONT
color=green>Total Submit:</FONT> 4168 <FONT color=green>Accepted
Submit:</FONT> 1703 </CENTER>
<HR>
<P>Let S = s1 s2 … s2n be a well-formed string of parentheses. S can be encoded
in two different ways:<BR></P>
<UL>
<LI>By an integer sequence P = p1 p2 … pn where pi is the number of left
parentheses before the ith right parenthesis in S (P-sequence).
<LI>By an integer sequence W = w1 w2 … wn where for each right parenthesis,
say a in S, we associate an integer which is the number of right parentheses
counting from the matched left parenthesis of a up to a. (W-sequence).
</LI></UL>
<P>Following is an example of the above encodings:<BR><BR>S
(((()()())))<BR>P-sequence 4 5 6666<BR>W-sequence 1 1 1456<BR><BR>Write a
program to convert P-sequence of a well-formed string to the W-sequence of the
same string.</P>
<P><BR><B>Input</B><BR><BR>The first line of the input contains a single integer
t (1 <= t <= 10), the number of test cases, followed by the input data for
each test case. The first line of each test case is an integer n (1 <= n
<= 20), and the second line is the P-sequence of a well-formed string. It
contains n positive integers, separated with blanks, representing the
P-sequence.</P>
<P><BR><B>Output</B><BR><BR>The output consists of exactly t lines corresponding
to test cases. For each test case, the output line should contain n integers
describing the W-sequence of the string corresponding to its given
P-sequence.</P>
<P><BR><B>Sample Input</B><BR><BR>2<BR>6<BR>4 5 6 6 6 6<BR>9<BR>4 6 6 6 6 8 9 9
9</P>
<P><BR><B>Sample Output</B><BR><BR>1 1 1 4 5 6<BR>1 1 2 4 5 1 1 3 9<BR></P>
<HR>
<FONT color=green size=+1>Problem Source: </FONT><I>Asia 2001, Tehran (Iran)</I>
<HR>
<CENTER><A href="http://acm.zju.edu.cn/submit.php?pid=1016">Submit</A>
<A href="http://acm.zju.edu.cn/list_problem.php?vol=1">Back</A>
<A
href="http://acm.zju.edu.cn/problem_status.php?pid=1016">Status</A> </CENTER>
<HR>
<CENTER>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD align=right width="65%"><A href="http://acm.zju.edu.cn/"><FONT
color=red>Zhejiang University Online Judge</FONT></A> <A
href="http://acm.zju.edu.cn/"><FONT color=red>V1.0</FONT></A></TD>
<TD align=right width="35%"><A href="http://www.zzhang.cn/"><FONT
color=#ffffff
size=-3>Book</FONT></A></TD></TR></TBODY></TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -