반응형
Notice
Recent Posts
Recent Comments
Link
동캄의 코딩도장
백준 9012 [괄호] 파이썬 본문
반응형
https://www.acmicpc.net/problem/9012
간단한 스택 구현 문제다.
import sys
N=int(sys.stdin.readline())
for _ in range(N):
lst=list(map(str,sys.stdin.readline().rstrip()))
stack=[]
flg=True
for element in lst:
if element=='(':
stack.append(element)
elif element==')' and stack:
stack.pop()
else:
flg=False
if flg and not stack:
print('YES')
else:
print('NO')
반응형
'코테 > BOJ' 카테고리의 다른 글
백준 2504 [괄호의 값] 파이썬 (0) | 2025.02.18 |
---|---|
백준 10799 [쇠막대기] 파이썬 (0) | 2025.02.13 |
백준 5397 [키로거] 파이썬 (0) | 2025.02.13 |
백준 1158 [요세푸스 문제] 파이썬 (0) | 2025.02.12 |
백준 3273 [두 수의 합] 파이썬 (0) | 2025.02.12 |