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

PROGRAMMING:Insert parenthesis sequence

Luz5年前 (2021-05-10)题库347
We define a bracket sequence as a sequence in which only '(', '') ', (,), (), ((etc.) are bracket sequences
We define the operation of inserting a pair of () into a sequence of brackets as an insertion operation.
For example, we insert () into (). In order to distinguish easily, we set the original bracket sequence () to AB, then we can form () AB, a () B, ab (),
In other words, we can insert () anywhere in the bracket sequence, including the beginning and end, but the inserted pair () must be adjacent to each other when inserting.
We consider a bracket sequence to be a graceful sequence if and only if the bracket sequence can be constructed as follows:
Start with an empty string, and then perform 0 or several operations, each operation inserts () into the current bracket sequence.
According to the above definition: (), (()), (() ()) are graceful bracket sequences, ((),) (, ()) are not graceful bracket sequences
###Input format:
Multi group input
Each line of input is given a bracket sequence composed of '(', ')', the length of which is less than or equal to 1000
There is no empty string
###Output format:
For each input and output line, if the current bracket sequence is graceful, output "yes" (without quotation marks)
Otherwise, output "no" (without quotation marks)
###Input example:
```in
()
(())
(()())
()()
(()
)(
()))
```
###Output example:
```out
YES
YES
YES
YES
NO
NO
NO
```







answer:If there is no answer, please comment