Skip to content

Commit

Permalink
solve : 9012 괄호
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 4, 2024
1 parent 4eb8896 commit 385bcb1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions python/boj_9012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from collections import deque

input = sys.stdin.readline


def solution(n, data):
answer = list()

for i in range(n):
target = data[i]
stack = deque()
flag = 1

for e in target:
if e == "(":
stack.append("(")
if e == ")":
if len(stack) == 0:
flag = 0
break
stack.pop()

if flag == 0 or len(stack) > 0:
answer.append("NO")
else:
answer.append("YES")

return answer


def display_result(answer):
for e in answer:
print(e)


def main():
n = int(input())
data = [list(map(str, input().rstrip())) for _ in range(n)]
answer = solution(n, data)
display_result(answer)


main()

0 comments on commit 385bcb1

Please sign in to comment.