목차

복서 정렬하기

ps
링크programmers.co.kr/…
출처프로그래머스
문제 번호85002
문제명복서 정렬하기
레벨Level 1
분류

기초

시간복잡도O(n^2)
인풋사이즈n<=1000
사용한 언어Python
해결날짜2021/09/07

풀이

코드

"""Solution code for "Programmers 85002. 복서 정렬하기".

- Problem link: https://programmers.co.kr/learn/courses/30/lessons/85002
- Solution link: http://www.teferi.net/ps/problems/programmers/85002
"""


def solution(weights, head2head):
    def compare_key(num):
        my_weight, my_h2h = weights[num - 1], head2head[num - 1]
        win_count, loss_count = my_h2h.count('W'), my_h2h.count('L')
        win_rate = (0 if win_count == 0
                    else win_count / (win_count + loss_count))
        win_against_heavier_count = sum(1 for w, h in zip(weights, my_h2h)
                                        if h == 'W' and w > my_weight)
        return (-win_rate, -win_against_heavier_count, -my_weight, num)

    return sorted(range(1, len(weights) + 1), key=compare_key)