-
스택. 괄호 열고 닫기 문제 (9012. 괄호)코테 준비/Stack, Queue 2022. 12. 8. 20:37
9012. 괄호 문제
t=int(input()) for i in range(t): ps=input() count=0 for j in ps: if j=='(': count+=1 elif j==')': count-=1 if count<0: break if count==0: print("YES") else: print("NO")
sentence=[] while True: s=input() if s=='.': break sentence.append(s) for i in sentence: count=[] k=0 #괄호가 먼저 닫히는 경우 for j in i: if j=='(' or j=='[': count.append(j) elif j==')': if not count or count[-1]=='[': k=-1 break elif count[-1]=='(': count.pop() elif j==']': if not count or count[-1]=='(': k=-1 break elif count[-1]=='[': count.pop() if not count and k!=-1: print("yes") else: print("no")
'코테 준비 > Stack, Queue' 카테고리의 다른 글
[프로그래머스] 롤케이크 자르기 (0) 2024.01.30 [프로그래머스] 기능개발 (0) 2023.01.23 [백준] 7662. 이중우선순위큐 (0) 2023.01.13 [프로그래머스] 이중우선순위큐 (0) 2023.01.12 Deque 모듈 사용하기 (10866. 덱) (0) 2022.12.08