์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ์ด์งํ์
- ์คํฐ๋
- Flutter
- ๊ตฌํ
- JavaScript
- Java
- ์ฐ์ จ์์
- BFS
- ํ๋ก๊ทธ๋๋จธ์ค
- ํ์ด์ฌ
- JS
- ๋ฌธ์์ด ํ์ฑ
- ์ผ์ฑsw์ญํ
- ์ฝ๋ฉํ ์คํธ
- DART
- ๋ชป๊ทธ๋ฆฌ์ง๋ง
- c#
- Algorithm
- ์๊ณ ๋ฆฌ์ฆ
- BAEKJOON
- sort
- ์๋ฃ๊ตฌ์กฐ
- ๋์ ํ๋ก๊ทธ๋๋ฐ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์นด์นด์ค
- ๊ทธ๋ํ ํ์
- ๋ฐฑ์ค
- ์ฝ๋ํธ๋ฆฌ
- programmers
- DP
Archives
- Today
- Total
Algo ์ฐ์
[Programmers] ๋คํธ๊ฒ์ ๋ณธ๋ฌธ
โถ ๋ฌธ์ :
โถ ์ฝ๋ :
def solution(dartResult):
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
divided = []
answer = []
temp = ''
for i in range(len(dartResult)):
if dartResult[i] in numbers and i == 0:
temp += dartResult[i]
elif dartResult[i] in numbers and dartResult[i-1] not in numbers:
divided.append(temp)
temp = dartResult[i]
elif i == len(dartResult) -1 :
temp += dartResult[i]
divided.append(temp)
else:
temp += dartResult[i]
index = 0
score = {i:0 for i in range(3)}
for expr in divided:
tempNum = ''
for c in expr :
if c in numbers:
tempNum += c
else:
if score[index] == 0:
score[index] = int(tempNum)
if c == 'S':
continue
elif c =='D':
score[index] **= 2
elif c =='T':
score[index] **= 3
elif c == '*':
score[index] *= 2
if index > 0:
score[index-1] *= 2
elif c == '#':
score[index] *= -1
index += 1
answer = sum(list(score.values()))
return answer
โถ ๋ฌธ์ ํด์ค :
1. ๊ทธ๋ฆฌ๋ํ๊ฒ ์ ๊ทผํ์๋ค
2. ์ด๊ธฐ dartResult์ ์ ์ฅ๋ ๋ฌธ์์ด์์ ๊ฐ๊ฐ์ ์คํ ์ด์ง๋ณ๋ก ๋ฌธ์์ด์ ๋๋๋ค.
3. ๋๋ ๋ฌธ์์ด๋ค์ ๋ํ ์ ์๋ฅผ score์ ์ ์ฅํ๋ฉด์ ์ ์๊ณ์ฐ์ ํด์ค๋ค.
โถ ์ถ๊ฐ ๋ด์ฉ :
+ ๋ค๋ฅธ์ฌ๋์ ํ์ด์ ์๋ ์ ๊ทํํ์์ ํ์ฉํ ๋ฐฉ๋ฒ์ ๊ผญ ์ฐธ๊ณ ํด๋ณด์
+ ์ ๊ทํํ์ ์ฌ์ฉ๋ฒ๋ ๊ผญ ๊ณต๋ถํด๋ณด์.
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] (Javascript) ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (0) | 2022.04.21 |
---|---|
[Programmers] (Javascript) ๋คํธ๊ฒ์ (0) | 2022.04.21 |
[Programmers] ๋น๋ฐ์ง๋ (0) | 2022.04.18 |
[Programmers] ์คํจ์จ (0) | 2022.04.18 |
[Programmers] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ (0) | 2022.04.18 |