Programming/Python & Data Structures
[Baekjoon/Python3] 9012번 괄호
HooNeee
2020. 12. 8. 21:54
[Baekjoon/Python3] 9012번 괄호
9012번: 괄호
괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고
www.acmicpc.net
t = int(input())
for i in range(t):
s = list(input())
cnt = 0
for j in s:
if j == '(':
cnt += 1
elif j == ')':
cnt -= 1
if cnt < 0:
print('NO')
break
if cnt > 0:
print('NO')
elif cnt == 0:
print('YES')