๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/17682
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ณ - ๋คํธ๊ฒ์
def solution(dartResult):
stack = []
dartResult = dartResult.replace("10", "A")
bonus = {'S': 1, 'D': 2, 'T': 3}
for i in dartResult:
if i.isdigit() or i=='A':
stack.append(10 if i == 'A' else int(i))
elif i in ['S', 'D', 'T']:
num = stack.pop()
stack.append(num ** bonus[i])
elif i == '#':
stack[-1] *= -1
elif i == '*':
num = stack.pop()
if len(stack):
stack[-1] *= 2
stack.append(2 * num)
return sum(stack)
์ฒ์์ 10์ด๋ผ๋ ์ซ์๋ฅผ ์ด๋ป๊ฒ ํด๊ฒฐํ ์ง ๊ณ ๋ฏผํ๋ค๊ฐ 10์ A์ด๋ผ๊ณ ๋์ฒดํ๊ณ if ๋ฌธ์์ A๋ฅผ ๋ค์ int(10)์ผ๋ก ๋ฐ๊ฟ์ฃผ๋๋ก ๊ตฌํํ์๋ค.
๊ทธ๋ฆฌ๊ณ bonus๋ฅผ ๋์ ๋๋ฆฌ๋ก ์ ์ธํ์ฌ ์ ๊ณฑ์ ๋ง๋ค์๋ค.