본문 바로가기

알고리즘/정렬

파이썬 | 백준 | 10825 | 국영수

https://www.acmicpc.net/problem/10825

solution

lambda x: (-국어, 영어, -수학, 이름)

 

※ 형식 에러

student = sorted(student, key=lambda x: (-x[1], x[2], -x[3), x[0]))

-x[1] → -int(x[1])

 

import sys

N = int(sys.stdin.readline())
student = [list((sys.stdin.readline().split())) for _ in range(N)]

student = sorted(student, key=lambda x: (-int(x[1]), int(x[2]), -int(x[3]), x[0]))

for stu in student:
    print(stu[0])

78708KB

500ms

 


다른 사람 풀이

from sys import stdin

n = int(stdin.readline().rstrip())
lst = []
for i in range(n):
    name, k, e, m = stdin.readline().split()
    lst.append((name, int(k), int(e), int(m)))

lst.sort(key=lambda item: item[0])
lst.sort(key=lambda item: item[3], reverse=True)
lst.sort(key=lambda item: item[2])
lst.sort(key=lambda item: item[1], reverse=True)

for item in lst:
    print(item[0])

44736KB
396ms