๋ฌธ์
https://www.acmicpc.net/problem/2504
ํ์ด
# ๋ฐฑ์ค 2504๋ฒ ๋ฌธ์ - ๊ดํธ์ ๊ฐ
bracket = list(input())
stack = []
answer = 0
tmp = 1
for i in range(len(bracket)):
if bracket[i] == '(':
stack.append(bracket[i])
tmp *= 2
elif bracket[i] == '[':
stack.append(bracket[i])
tmp *= 3
elif bracket[i] == ')':
if not stack or stack[-1] == '[':
answer = 0
break
if bracket[i-1] == '(':
answer += tmp
stack.pop()
tmp //= 2
else:
if not stack or stack[-1] == '(':
answer = 0
break
if bracket[i-1] == '[':
answer += tmp
stack.pop()
tmp //= 3
if stack:
print(0)
else:
print(answer)
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver4] 1269๋ฒ_๋์นญ ์ฐจ์งํฉ (0) | 2023.02.09 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 1303๋ฒ_์ ์-์ ํฌ (0) | 2023.02.09 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1068๋ฒ_ํธ๋ฆฌ (0) | 2023.01.04 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 2573๋ฒ_๋น์ฐ (0) | 2023.01.04 |
๐ฉ [๋ฐฑ์ค] [Python] 13549๋ฒ_์จ๋ฐ๊ผญ์ง 3 (0) | 2022.12.17 |