The Interview Problem
시간 제한1초메모리 제한2048 MB
괄호 문자열을 만들면서 숫자가 나올 때마다 그만큼 문자를 지울 수 있을 때, 균형 잡힌 괄호열을 만들 수 있는지 판정한다.
문제
You are given a string consisting of parentheses ("(" and ")") and digits ("0" through "9"). From the string , you construct another string by considering every character of in order and performing the following operations based on the character values:
- "
(": append "(" to . - "
)": append ")" to . - : delete any characters from . It is guaranteed that it is always possible to do so. The deleted characters don't need to be consecutive.
Is it possible to construct to be a balanced bracket sequence?
입력
The first line contains an integer (), the number of test cases.
For each test case, you are given a non-empty string consisting of parentheses and digits ("()0123456789"). The length of the string will be at most characters.
It is guaranteed that the total length of the strings will not exceed characters.
출력
For each test case, output "YES" if it is possible to construct to be a balanced bracket sequence, and "NO" otherwise.
You may output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.