Skip to content

Commit

Permalink
solve : 4949 균형잡힌 세상
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 10, 2024
1 parent c006c15 commit 570a6f2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions python/boj_4949.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
from collections import deque

input = sys.stdin.readline


def solution(data):
stack = deque()
for e in data:
if e == "(":
stack.append("(")
if e == ")":
if len(stack) == 0:
return "no"
top = stack.pop()
if top != "(":
return "no"

if e == "[":
stack.append("[")
if e == "]":
if len(stack) == 0:
return "no"
top = stack.pop()
if top != "[":
return "no"

if len(stack) > 0:
return "no"

return "yes"


def display_result(answer):
print(answer)


def main():
while True:
data = list(map(str, input().rstrip()))
if len(data) == 1 and data[0] == '.':
break
answer = solution(data)
display_result(answer)


main()

0 comments on commit 570a6f2

Please sign in to comment.