본문 바로가기

백준문제풀이

[백준 문제풀이] 9012번 : 괄호

https://www.acmicpc.net/problem/9012

 

9012번: 괄호

괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고

www.acmicpc.net

1. 소스코드

T=int(input())

for i in range(T) :
    case = list(input())
    l_count=0
    r_count=0
    for j in case:
        if j=="(":
            l_count+=1
        elif j==")":
            r_count+=1
        if l_count < r_count:
            print('NO')
            break

    if l_count==r_count:
        print("YES")
    elif l_count > r_count:
        print("NO")