Code only in C language A bracket is considered to be any one of the following characters:
Fantastic news! We've Found the answer you've been seeking!
Question:
Code only in C language
Transcribed Image Text:
A bracket is considered to be any one of the following characters: (, ), { }. L or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e. (, L or () occurs to the left of a closing bracket (i.e., ). ], or }) of the exact same type. There are three types of matched pairs of brackets: (0. (),and (). A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For example, ([0)} is not balanced because the contents in between { and } are not balanced. The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of parentheses encloses a single, unbalanced closing square bracket, ]. By this logic, we say a sequence of brackets is balanced if the following conditions are met: a) It contains no unmatched brackets. b) The subset of brackets enclosed within the confines of a matched pair of brackets is also a matched pair of brackets. Given n strings of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, return YES. Otherwise, return NO. INPUT: The first line contains a single integer n, the number of strings. Each of the next n lines contains a single string s, a sequence of brackets. CONSTRAINTS: 1 A bracket is considered to be any one of the following characters: (, ), { }. L or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e. (, L or () occurs to the left of a closing bracket (i.e., ). ], or }) of the exact same type. There are three types of matched pairs of brackets: (0. (),and (). A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For example, ([0)} is not balanced because the contents in between { and } are not balanced. The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of parentheses encloses a single, unbalanced closing square bracket, ]. By this logic, we say a sequence of brackets is balanced if the following conditions are met: a) It contains no unmatched brackets. b) The subset of brackets enclosed within the confines of a matched pair of brackets is also a matched pair of brackets. Given n strings of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, return YES. Otherwise, return NO. INPUT: The first line contains a single integer n, the number of strings. Each of the next n lines contains a single string s, a sequence of brackets. CONSTRAINTS: 1
Expert Answer:
Related Book For
Canadian Income Taxation planning and decision making
ISBN: 9781259094330
17th edition 2014-2015 version
Authors: Joan Kitunen, William Buckwold
Posted Date:
Students also viewed these algorithms questions
-
Write a C language program... The following code will implement three functions supported by a stack. Push ( ): It adds elements on top of the stack. It takes O (1) O (1) time as each element is...
-
How would I code in C language to create a game in which a player goes through a series of rooms in which they can find a prize or a monster to fight?
-
A language class has only 3 students A,B and C and they independently attend the class. The probabilities of the attendance of A, B and C on a given day are 1/2, 1/3 and 3/4 respectively. Find the...
-
Explain how teacher knowledge of context impacts the development of meaningful learning and teaching for any particular group of young children. Cite at least three relevant sources from the...
-
Summarize in one sentence how each of the following organizations failed to practice risk management: a. Metallgesellschaft b. Orange County c. Barings d. Procter & Gamble
-
Reska, Inc., has constructed a long euro straddle. A call option on euros with an exercise price of $1.10 has a premium of $.025 per unit. A euro put option has a premium of $.017 per unit. Some...
-
Construct a bar graph for each of the following (assume the independent variable is group and the dependent variable is time): a. Group \(\mathrm{A}(N=5, M=4.00, s=1.58)\); Group B \((N=5, M=6.00,...
-
Calculate the Loyalty Discount % in cell F16. Notice that the discount rates depend both on the loyalty status of the customer (gold or silver) and the total price of the items purchased (cell F14)....
-
Richards Corporation had net income of $238,707 and paid dividends to common stockholders of $47,500. It had 56,700 shares of common stock outstanding during the entire year. Richards Corporation's...
-
Wolfe Industries pays its employees on a semimonthly basis. Using the wagebracket tables in Appendix C, compute the federal income tax deductions for the following employees of Wolfe Industries. No...
-
Which of the following statements is true according to the graph? The economy is producing the maximum amount possible given the current resources. The economy is producing at a real GDP greater...
-
Solve these 2 question by using the derivative y = 2x (x - 4x) at x=2 y=x3x + 5 at x = 4
-
Compare futures contract to forward contract focusing on the differences. You are expected to be able to calculate speculation profits by taking long or short positions. You are expected to be able...
-
1. Prepare the income Statement. 2. Prepare the Balance Sheet. 3. Prepare the Closing Entries. 4. Prepare the post-closing trial balance.
-
3.2d (5 points) The following $625 million fund has completed its 10-year life. Information on the fund is below. (in $millions) Investments Carried interest Distribution to LPs Portfolio value after...
-
The variable income (yearly) is examined in a regression setting where the predictor variable is lag (1) of income and the following output is produced. a) Write down the regression equation. (3...
-
An electron (me = 9.11 1031 kg) with velocity v = (2.50 106 m/s)i + (3.00 106 m/s)j moves through a uniform magnetic field B = (0.20 T)i (0.15 T)k. Calculate the (a) magnetic force exerted on the...
-
Find an equation of the given line. Slope is -2; x-intercept is -2
-
Jane owns all of the shares of J Ltd., a Canadian-controlled private corporation with investments in numerous Canadian public companies. Her husband, Mike, owns all of the shares of M Ltd., a...
-
Barry Yuen is district sales manager for a Vancouver-based distribution company. He has requested that you help him establish his employment income for tax purposes for the 20X3 taxation year. He has...
-
Identify and briefly explain two alternative tax treatments that can apply when assets are transferred to a corporation by a shareholder or a proposed shareholder.
-
What percentage of women have red blood cell counts in the normal range from 4.2 to 5.4? Assume that red blood cell counts of women are normally distributed with a mean of 4.577 and a standard...
-
Find P 80 , the 80th percentile for the red blood cell counts of women.
-
A new integrated circuit board is being developed for use in computers. In the early stages of development, a lack of quality control results in a 0.2 probability that a manufactured integrated...
Study smarter with the SolutionInn App