Parentheses are important characters in programming -- they define the order of operations and organize information. That is, as long as they are properly balanced. Parentheses are balanced when the opening and closing brackets match with one another and are themselves nested within balanced parentheses. For example:

() - balanced: opening is matched with a closing
(() - not balanced: one of the opening brackets has no match
([)] - not balanced: the contents inside of () are not balanced

Write a program that checks for valid parentheses. Valid characters are any of the three parenthesis types: (), [], {}. Each string will be entered from the keyboard on a separate line. Each string will contain at least o hine and at most 26 parentheses. For each input string in which the parentheses match correctly, print the string, placing two spaces in front of each parenthesis. On the next line, print a number for each left and right parenthesis to show the matching. The first '(' in an input string is numbered 1, the second '(' is numbered 2, the third '(' is numbered 3, and so on. Each ')' will have the same number as its matching '('. Print each number right justified in a 3-character field. For each string in which the parentheses do not match, print only the message: Parentheses do not match! A stack data structure must be used, do not use the built in Java/C++ stack class. Refer to the sample output below.

Sample Run:

Enter a string: (()())((()())())
( ( ) ( ) ) ( ( ( ) ( ) ) ( ) )
1 2 2 3 3 1 4 5 6 6 7 7 5 8 8 4
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.