-
2504 괄호의 값 - 스택코테 대비 python/백준 2023. 2. 12. 08:31
https://www.acmicpc.net/problem/2504
s = list(input()) stack = [] res = 1 result = 0 # 1~4번째 과정 시작 for i in range(len(s)): if s[i]=='(': res *= 2 stack.append(s[i]) elif s[i]=='[': res *= 3 stack.append(s[i]) elif s[i]==')': if not stack or stack[-1]!='(': result = 0 break if s[i-1]=='(': result += res res //= 2 stack.pop() elif s[i]==']': if not stack or stack[-1]!='[': result = 0 break if s[i-1]=='[': result += res res //= 3 stack.pop() if stack: print(0) else: print(result)
'코테 대비 python > 백준' 카테고리의 다른 글
11279 최대 힙 (1) 2023.02.18 22942 데이터 체커 - 스택 (0) 2023.02.12 10989 수 정렬하기 정렬 잡기술 (0) 2023.02.06 1158 요세푸스 (0) 2023.02.06 2231 분해합 (0) 2023.02.03