-->
当前位置:首页 > 题库

PROGRAMMING:parenthesis matching

Luz5年前 (2021-05-10)题库364
### Description
Given a string $$P$$ only consist of characters with $$()$$, $$[]$$ and $$\{\}$$. Now BaoBao wants to know whether $$P$$ can form a valid bracket string.
We define a **pair** that for each (, we can find a ) behind it. In the same way, \[ and { also can find their ] and }.
For example:
* In string "()": ( and ) formed a **pair**;
* In string "\[)(]": \[ and ] formed a **pair**, but ( and ) are not;
* In string "{(})\[{(}])", there exist 5 **pairs**.
And a **valid** bracket string means the number of **pair**s in a string $$N$$ can satisfy $$N = |P| \div 2$$ where $$|P|$$ means the length of string $$P$$.
For example, "(()())", "({})", "(\[)]" and "{\[(]})" are the valid bracket string, but "(()", ")(" and "{{(})" are invalid.
### Input:
The first line contains a integer $$T(1 \leq T \leq 100)$$, which indicates the number of test cases.
The next $$T$$ lines, each line only contains a bracket string $$P_ i(|P_ i| \leq 2 \times 10^5)$$.
It guaranteed that the sum of $$|P_ i| \leq 2 \times 10^5$$.
### Output:
For each test cases, you just output "YES" if the string is valid or "NO" for not valid.
### Sample Input:
```in
four
({})
{{}}
({[}])
}{
```
### Sample Output:
```out
YES
YES
YES
NO
```







answer:If there is no answer, please comment