Question
Question 4: Coding Parenthesis (Bonus 10%) Let S be a well-formed string of parenthesis. S can be encoded into P-sequence and W-sequence. P-sequence is the
Question 4: Coding Parenthesis (Bonus 10%)
Let S be a well-formed string of parenthesis. S can be encoded into P-sequence and W-sequence. P-sequence is the sequence of the numbers of left parentheses before its right parenthesis. W-sequence is the sequence of the numbers of right parentheses counting from the matched left parenthesis.
S P-sequence W-sequence
(((()()()))) 4 5 6666 1 1 1456
Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as lab4-q4.c.
Input file: The first line 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 by a space.
Output file: A line contains n integers, separated by a space, describing the W-sequence of the string corresponding to its given P-sequence
Sample Input:
6 456666
Sample Output:
111456
Question 4: Coding Parenthesis (Bonus 10%) Let S be a well-formed string of parenthesis. S can be encoded into P-sequence and W-sequence. P-sequence is the sequence of the numbers of left parentheses before its right parenthesis. W-sequence is the sequence of the numbers of right parentheses counting from the matched left parenthesis. S ((((())) P-sequence 4 5 6666 W-sequence 1 1 1456 Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as "lab4-94.c". Input file: The first line is an integer n (1 sns 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers separated by a space. Output file: A line contains n integers, separated by a space, describing the W-sequence of the string corresponding to its given P-sequence Sample Input: 6 4 5 6 6 6 6 Sample Output: 1 1 1 4 5 6Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started