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
Carnegie Mellon University Robotics Institute | Research Associate | Developing For Our Lives, 세상에 기여하는 삶을 살고자 개발하고 있습니다

0개의 댓글

관련 채용 정보