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

PROGRAMMING:Graceful sequence of brackets

Luz5年前 (2021-05-10)题库424
One day, Xiao Ming was very bored, so he wanted to find something to play with. So he found that brackets () were very interesting, and he learned a new skill,
Insert a pair of small brackets () into a bracket sequence. The insertion rule is that the position of the left bracket '('should be smaller than that of the right bracket') 'does not require that the inserted left and right brackets are adjacent,
For example, in the following, for the convenience of distinguishing, we take AB as the original bracket sequence
Insert () into () to form () AB (a) B (AB) a () B a (b) AB (), where a represents the left bracket of the original bracket sequence and B represents the right bracket of the original bracket sequence.
Xiao Ming thinks that a bracket sequence is 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