Pro.ID21103 TitleParencodings Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21103 AC75 Submit144 Ratio52.08% 时间&空间限制描述Let S = s1s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:
Following is an example of the above encodings: S (((()()()))) Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string. 输入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. 输出Description Let S = s1s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:
Following is an example of the above encodings: S (((()()()))) Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string. Input 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. Output The output file 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. Sample Input 2 Sample Output 1 1 1 4 5 6 Source 样例输入2 样例输出1 1 1 4 5 6 作者 |