반응형
def solution(dartResult):
score_list = [ f'{idx}' for idx in range(11)]
dart_list = { 'S' : 1, 'D' : 2, 'T': 3 }
check_arr = 0
answer_arr = []
for idx in range(len(dartResult)):
if dartResult[idx] in score_list:
if dartResult[idx] == '0' and dartResult[idx-1] == '1':
check_arr = 10
else:
check_arr = dartResult[idx]
if dartResult[idx] == 'S' or dartResult[idx] == 'D' or dartResult[idx] == 'T':
answer_arr.append(int(check_arr)**dart_list[dartResult[idx]])
if dartResult[idx] == '#':
pop_number = answer_arr.pop()
answer_arr.append(-int(pop_number))
if dartResult[idx] == '*':
sum_answer = 0
if len(answer_arr) == 1:
value1 = answer_arr.pop() * 2
answer_arr.append(value1)
else:
value1 = answer_arr.pop() * 2
value2 = answer_arr.pop() * 2
answer_arr.append(value2)
answer_arr.append(value1)
return sum(answer_arr)
반응형
'삽집하는 개발들 > 알고리즘' 카테고리의 다른 글
[49일차][Lv1][프로그래머스][132267]콜라 문제 (0) | 2023.08.29 |
---|---|
[49일차][Lv1][프로그래머스][2023 Dev-Matching: 웹 백엔드 개발][77484]로또의 최고 순위와 최저 순위 (0) | 2023.08.29 |
[47일차][Lv1][프로그래머스][120869]외계어 사전 (4) | 2023.08.24 |
[46일차][프로그래머스][136798]기사단원의 무기 (2) | 2023.08.22 |
[45일차][프로그래머스][42889][2019 KAKAO BLIND RECRUITMENT]실패율 (4) | 2023.08.22 |