#K73372. Bracket Nesting Checker
Bracket Nesting Checker
Bracket Nesting Checker
This problem requires you to determine whether a given string containing various types of brackets is correctly nested. The valid brackets are: \( ( ) \), \( { } \), \( [ ] \) and \( \). A string is considered correctly nested if every opening bracket has a corresponding closing bracket in the correct order. For example, the string "()" is correctly nested, while "{[}" is not.
Your task is to read an integer \( T \) from standard input, representing the number of test cases, followed by \( T \) lines each containing a string of brackets. For each test case, output YES
if the string is correctly nested, otherwise output NO
.
inputFormat
The input is read from standard input and is formatted as follows:
- The first line contains a single integer \( T \) (\( 1 \leq T \)) indicating the number of test cases.
- The following \( T \) lines each contain a string \( S \) consisting only of the characters
(
,)
,{
,}
,[
,]
,<
, and>
.
outputFormat
For each test case, output one line containing YES
if the bracket string is correctly nested, or NO
otherwise. The result for each test case should be printed in the same order as the input.
3
()
{[()]}
{[}
YES
YES
NO
</p>