From 570a6f2a6a0331da1a4d8b7f353432a5f33ef91f Mon Sep 17 00:00:00 2001 From: wwan13 Date: Fri, 10 May 2024 11:18:07 +0900 Subject: [PATCH] =?UTF-8?q?solve=20:=204949=20=EA=B7=A0=ED=98=95=EC=9E=A1?= =?UTF-8?q?=ED=9E=8C=20=EC=84=B8=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/boj_4949.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 python/boj_4949.py diff --git a/python/boj_4949.py b/python/boj_4949.py new file mode 100644 index 0000000..b5b7315 --- /dev/null +++ b/python/boj_4949.py @@ -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() \ No newline at end of file