#C5626. Balanced Brackets Checker
Balanced Brackets Checker
Balanced Brackets Checker
You are given an integer T
followed by T
strings. Each string is composed of bracket characters: (
, )
, {
, }
, [
, and ]
. For each string, determine whether the brackets are balanced. A string is considered balanced if all opening brackets have a corresponding closing bracket in the correct order.
The solution must read from standard input (stdin
) and write to standard output (stdout
). The first line of input contains the integer T
, and each of the following T
lines contains a test case.
For each test case, output a single line containing YES
if the string is balanced or NO
otherwise.
inputFormat
The first line contains an integer T
indicating the number of test cases. Each of the following T
lines contains a single string of brackets.
Example:
5 ([]) ([)] {{[[(())]]}} [] [{()}()]
outputFormat
For each test case, output one line with either YES
or NO
based on whether the brackets in the test case are balanced.
Example:
YES NO YES YES YES## sample
5
([])
([)]
{{[[(())]]}}
[]
[{()}()]
YES
NO
YES
YES
YES
</p>