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)