규칙을 정리해보면 아래와 같다.
이를 코드로 구현해서 완성하였다.
import sys
input = sys.stdin.readline
n = int(input().rstrip())
for _ in range(n):
ps = list(input().rstrip())
i = 1
while (i != len(ps) and len(ps) != 0):
if (ps[0] == ')'):
break
if (ps[i] == ')'):
ps.pop(i)
ps.pop(i-1)
i = 1
else:
i += 1
if (len(ps) == 0):
print("YES")
else:
print("NO")
'백준' 카테고리의 다른 글
[백준] 1966번 파이썬 (프린터 큐) (0) | 2024.02.23 |
---|---|
[백준] 11866번 파이썬 (요세푸스 문제 0) (0) | 2024.02.22 |
[백준] 2609번 파이썬 (최대공약수와 최소공배수) (0) | 2024.02.19 |
[백준] 2164번 파이썬 (카드2) (0) | 2024.02.19 |
[백준] 1929번 파이썬 (소수 구하기) (0) | 2024.02.18 |