Time Limit: 1 Sec Memory Limit: 128 MB
There are n brackets, and you want to know whether they are matched. The brackets will only contain {, }, (, ), [, ]. Here is the matching rules. For example, {{[}]} is not matching, but [{{}}()] is matching. Please write a program to check whether the given string is matched or not.
The first line will be an integer
For each test case, print YES
if the test case is a matching case. Otherwise, print NO
.
7
1
(
2
()
2
{]
6
[(){}]
4
(])[
8
[[{{}}]]
6
[][{]]
NO
YES
NO
YES
NO
YES
NO