#C12642. Balanced Brackets Checker
Balanced Brackets Checker
Balanced Brackets Checker
Given a string S
which may contain various characters including parentheses, square brackets, and curly braces, your task is to determine whether the brackets in the string are balanced.
A string is considered balanced if:
- Every opening bracket has a corresponding closing bracket.
- The pairs of brackets are properly nested.
In particular, the following bracket pairs are valid: \( ( ) \), \( \{ \} \), and \( [ ] \).
Note that characters that are not one of these six brackets should be ignored. For example, the string "hello world" is considered balanced.
inputFormat
The input consists of a single line containing the string S
. The string may include spaces and any printable characters.
Input is provided via standard input (stdin).
outputFormat
Output a single line with either True
if the string is balanced, or False
otherwise. The output should be printed to standard output (stdout).
()
True