9012 :괄호

서희찬·2021년 11월 30일
0

백준

목록 보기
76/105

문제

코드

n = int(input())
for _ in range(n):
    cnt=0
    stack = input() 
    for stacks in stack:

        if(cnt<0): #조건탈락 
            break
        
        if stacks =='(':
            cnt+=1
        else : #")"
            cnt-=1 
        
    if(cnt==0):
        print("YES")
    else :
        print("NO")

해설

괄호를 cnt를 더하고 뺌으로서 구분해주는 문제이다.

profile
부족한 실력을 엉덩이 힘으로 채워나가는 개발자 서희찬입니다 :)

0개의 댓글