-
Notifications
You must be signed in to change notification settings - Fork 0
/
다트 게임.py
47 lines (43 loc) · 1.47 KB
/
다트 게임.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Level 1 다트 게임.py
def solution(dartResult):
dartResult = list(dartResult) #list로 변환
point = [] #각 점수 저장
star = [] #*의 위치 저장
sharp = [] # #의 위치 저장
count = 0 #숫자 번호
i = 0
while i < len(dartResult)-1 :
if dartResult[i].isdigit() : #정수일 경우
if dartResult[i]=="1" and dartResult[i+1]=="0": #10일 경우
temp = 10
i += 1
else :
temp = int(dartResult[i])
if dartResult[i+1] == "S" : #보너스만큼 계산
temp = temp**1
elif dartResult[i+1] == "D" :
temp = temp**2
elif dartResult[i+1] == "T" :
temp = temp**3
point.append(temp)
if i+2 < len(dartResult) :
if dartResult[i+2] == "*" : #*일 경우
star.append(count) #*의 위치 저장
i += 3
elif dartResult[i+2] == "#" : ##일경우
sharp.append(count) ##의 위치 저장
i += 3
else :
i += 2
else :
i += 2
count += 1
for i in range(len(star)) : #*옵션 적용
if star[i] == 0 :
point[0] *= 2
else :
point[star[i]] *=2
point[star[i]-1] *= 2
for i in range(len(sharp)) : ##옵션 적용
point[sharp[i]] *= -1
return sum(point)