Created
March 21, 2019 03:12
-
-
Save rpf5573/143fc2b3693b4a37041f49d239a3f954 to your computer and use it in GitHub Desktop.
2018 카카오 코딩테스트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from : https://programmers.co.kr/learn/courses/30/lessons/42889?language=python3 | |
def solution(N, stages): | |
totalPlayers = len(stages) | |
playersInStages = [0 for _ in range(N+1)] | |
for i in range(len(stages)): | |
z = stages[i]-1 | |
playersInStages[z] = playersInStages[z]+1 | |
failureRates = [0 for _ in range(N)] | |
clearedPlayers = 0 | |
for i in range(len(playersInStages)-1): | |
if totalPlayers - clearedPlayers == 0: | |
failureRates[i] = 0 | |
continue | |
failureRates[i] = float(playersInStages[i]) / float(totalPlayers - clearedPlayers) | |
clearedPlayers += playersInStages[i] | |
answer = [0 for _ in range(N)] | |
for i in range(len(failureRates)): | |
rank = N | |
for z in range(len(failureRates)): | |
if i == z: | |
continue | |
if failureRates[i] >= failureRates[z]: | |
rank = rank - 1 | |
stage = i + 1 | |
for k in range(rank-1, N): | |
if answer[k] == 0: | |
answer[k] = stage | |
break | |
return answer | |
t1 = (5, [2,1,2,6,2,4,3,3]) | |
t2 = (4, [4,4,4,4,4]) | |
t3 = (2, [2,2,2,2,2]) | |
t4 = (3, [1,2,1,2,1]) | |
print( solution(t1[0], t1[1]) ) # [3, 4, 2, 1, 5] | |
print( solution(t2[0], t2[1]) ) # [4, 1, 2, 3] | |
print( solution(t3[0], t3[1]) ) # [2, 1] | |
print( solution(t4[0], t4[1]) ) # [2, 1, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment