알고리즘(python)/자료구조
[Python]Stack 백준 9012
개발일기
2019. 12. 14. 23:21
반응형
문제
https://www.acmicpc.net/problem/9012
스택 문제지만 스택을 사용하지는 않았다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import sys n=int(input()) while(n>0): n-=1 vps=sys.stdin.readline().strip() stack_len = 0 for i in vps: if i=='(': stack_len+=1 elif i==')': stack_len-=1 if stack_len<0: #(보다 )가 먼저 많이 나왔을때 ex>())( print("NO") break if stack_len==0: print("YES") elif stack_len>0: #(가 더 많을때 print("NO") | cs |
반응형