#t429. 字符串匹配问题

字符串匹配问题

String Bracket Matching

Problem Background

Special for beginners, ^_^

Problem Description

A string contains only the brackets (), [], <>, {}. Determine whether the brackets in the input string are matched. If brackets are nested, from inside to outside they must be in the order <>, (), [], {}. For example, input [()] outputs YES, while input ([]), ([)] should output NO.

Input Format

The first line is an integer nn, indicating how many bracket strings follow. The following nn lines each contain a bracket string of length at most 255255.

Output Format

Output nn lines, each being YES or NO. These words must be printed exactly as shown (do not translate).

Sample Input 1

5
{}{}<><>()()[][]
{{}}{{}}<<>><<>>(())(())[[]][[]]
{{}}{{}}<<>><<>>(())(())[[]][[]]
{<>}{[]}<<<>><<>>>((<>))(())[[(<>)]][[]]
><}{{[]}<<<>><<>>>((<>))(())[[(<>)]][[]]

Sample Output 1

YES
YES
YES
YES
NO

Constraints

Time limit 1s, memory limit 1024KiB for each test case.