Created
October 4, 2021 11:57
-
-
Save JungTag/da3a16ef7399bf0cc22367b795004d95 to your computer and use it in GitHub Desktop.
6주차_복서정렬하기 - 영택
This file contains hidden or 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
| # https://programmers.co.kr/learn/courses/30/lessons/85002 | |
| def solution(weights, head2head): | |
| answer = [] | |
| record_list = get_record_list(weights, head2head) | |
| record_list.sort(key = lambda x: (-x[0], -x[1], -x[2], x[3])) | |
| answer = [record[3]+1 for record in record_list] | |
| return answer | |
| def get_record_list(weights, head2head): | |
| record_list = [] | |
| for i, i_weight in enumerate(weights): | |
| winning_rate = 0 | |
| match_cnt = 0 | |
| winning_cnt = 0 | |
| heavy_winning_cnt = 0 | |
| for j, j_weight in enumerate(weights): | |
| result = head2head[i][j] | |
| if result == 'W': | |
| match_cnt += 1 | |
| winning_cnt += 1 | |
| if i_weight < j_weight: | |
| heavy_winning_cnt += 1 | |
| if result == 'L': | |
| match_cnt += 1 | |
| if match_cnt != 0: | |
| winning_rate = winning_cnt / match_cnt | |
| record_list.append([winning_rate, heavy_winning_cnt, i_weight, i]) | |
| return record_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment