https://school.programmers.co.kr/learn/courses/30/lessons/17682
문제가 길어 링크 대체 하겠습니다
func solution(_ dartResult:String) -> Int {
// split을 활용하여 숫자 문자 나누기
var numbers = dartResult.split(whereSeparator: { $0.isLetter || $0 == "*" || $0 == "#"})
var letters = dartResult.split(whereSeparator: { $0.isNumber })
var answer = numbers.map{ Int($0)! }
print(answer)
for (index, element) in letters.enumerated() {
for c in element {
switch c {
case "D":
answer[index] = answer[index] * answer[index]
case "T":
answer[index] = answer[index] * answer[index] * answer[index]
case "*":
if (index != 0) {
answer[index] *= 2
answer[index - 1] *= 2
} else {
answer[index] *= 2
}
case "#":
answer[index] *= -1
default:
break
}
}
}
return answer.reduce(0, +)
}