- 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/17682
- 정답 풀이 :
def solution(dartResult):
answer = []
index = 0
score_idx = -1
while index < len(dartResult):
if dartResult[index].isdigit():
end_index = index
#두 자리 수가 있는 경우에 대비해서
while dartResult[end_index].isdigit():
end_index += 1
if dartResult[end_index] == 'S':
answer.append(int(dartResult[index:end_index]))
elif dartResult[end_index] == 'D':
answer.append(int(dartResult[index:end_index]) ** 2)
elif dartResult[end_index] == 'T':
answer.append(int(dartResult[index:end_index]) ** 3)
score_idx += 1
index = end_index + 1
else:
if dartResult[index] == '*':
if score_idx == 0 :
answer[score_idx] *= 2
else:
answer[score_idx - 1] *= 2
answer[score_idx] *= 2
elif dartResult[index] == '#':
answer[score_idx] *= -1
index += 1
return sum(answer)
'코딩테스트 > 기출' 카테고리의 다른 글
[2019 KAKAO BLIND RECRUITMENT / 프로그래머스] 42888번 : 오픈 채팅방 (0) | 2022.09.06 |
---|---|
[2022 kakao tech intership / 프로그래머스] 118667번 : 두 큐 합 같게 만들기 (0) | 2022.09.06 |
[연습문제 / 프로그래머스] 12940번 : 최대공약수와 최소공배수 (0) | 2022.08.31 |
[연습문제 / 프로그래머스] 12930번 : 이상한 문자열 만들기 (0) | 2022.08.29 |
[연습문제 / 프로그래머스] 12915번 : 문자열 내 마음대로 정렬하기 (0) | 2022.08.28 |