#C7584. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
Given a string s
consisting solely of characters: '(', ')', '[', ']', '{', and '}', determine whether the sequence of parentheses is valid.
An input string is valid if:
- Any open bracket must be closed by the same type of bracket.
- Open brackets must be closed in the correct order.
You are required to read the string from the standard input and print True
if the string is valid or False
otherwise. The validation should follow the standard rules for matching parentheses, where every opening bracket has a corresponding closing bracket in the correct order.
The solution must handle edge cases such as an empty string (which is considered valid) and strings with a single unmatched bracket.
inputFormat
The input consists of a single line containing a string s
with characters among '(', ')', '[', ']', '{', and '}'.
Note: The string can be empty.
outputFormat
Output a single line: True
if the input string is a valid sequence of parentheses, or False
otherwise.
()
True