Computers and Technology

You are given a string consisting of parenthesis style characters ( ) [ ] and { }. A string of this type is said to be correct if: (a) It is an empty string. (b) If string A is correct and string B is correct then string AB is correct. (c) If A is correct then (A), [A] and {A} are all correct. You are to write a program that takes as input from the keyboard a series of strings of this type that can be of any length. The first line of input will contain a single integer n telling you how many strings you will be testing. Following that integer will be n lines (each ending in a new line character) that represent the strings you are supposed to test with one string per line. Your program should output Yes if a given string is correct and No otherwise. For example if the user types the following as input 3 ([]) (([{}]))) ([()[]()])() Then your program should give the following output: Yes No Yes You will note that if you do your program correctly there is no prompt for data and the yes and no answers will be interspersed with your input data when you enter it manually. The following would be a more accurate representation of what you see on the screen when you cut and paste the input into your program. 3 ([]) Yes (([{}]))) No ([()[]()])() Yes You may find it useful to use a text file for testing your code so that you do not have to keep retyping the tests. You can do this from the command line by typing the name of the executable file followed by a less than sign and the name of your file. For example, if my executable is named day7 then I could type: day7 < input. txt This would redirect standard input so that the input instead comes from the file named input. txt. You should note that the input. txt file needs to be in the same directory as your executable file for the above command to work. Alternatively you can give the complete path information for the input file. You may not assume anything about the size of the test strings coming in. In fact, some of the test strings may be hundreds of thousands of characters long… COMP1020 Day 7 Daily Adams Summer 2016 How do you solve it? The trick to this problem is realizing that our stack interface can be used to solve the problem. One way to approach the problem is to read in a character, if it is a left marker then push it onto the stack. If it is a right marker then check the top of the stack (if it exists), if it is the correct left marker then pop it out and continue testing the string. If you encounter a right marker and the top of the stack is not the left hand version of the marker you just picked up or the stack is empty then you can determine that the string is not correct, clear the stack and go on to the next example. If you finish a whole string (encounter a new line) without encountering a problem then you can determine that the input string is correct. You should submit your program to an online checker that will test it for a small set of input values by going to uva. onlinejudge. org, making an account, and submitting your solution as a solution to problem 673. Even though the problem I have given you is a bit harder than the problem given there, your solution to this problem should have no problem solving their version of problem 673 that they have on the site. Submit your main. c and your stack. c, stack. h and any other support files you need along with a text file containing a copy of the email you get from the UVA online judge. Your stack. c implementation file should contain an implementation for the stack that can hold characters instead of integers and should use a linked list implementation of the stack.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:10, Tatertotzzzz
Write a method that accepts a string object as an argument and returns the number of words it contains. for instance, if the argument is "four score and seven years ago", the method should return the number 6. demonstrate the method in a program that asks the user to input a string and then passes that string into the method, printing out whatever the method returns.
Answers: 3
image
Computers and Technology, 22.06.2019 10:30, JeroMii
Think about a recent customer service experience - either positive or negative. write a brief summary of that experience. now think about those four characteristics we look for in customer service representatives. how did the representative in your example stack up? write down your answer and give specific examples.
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, jayjay5246
What is the term for water wave that is created by an underwater earthquake
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, cireland
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits. now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order. finally, output thedigits in thearray. use at least two functions to organize your program.
Answers: 3
Do you know the correct answer?
You are given a string consisting of parenthesis style characters ( ) [ ] and { }. A string of this...

Questions in other subjects: