Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

years.

Answered: 1 week ago