파이썬) 객체 생성,접근자 객체리스트 정렬

백준 10835번

# 백준 10835번
import sys


class Student:
    def __init__(self, name, native_lang, english, math):
        self.name = name
        self.native_lang = native_lang
        self.english = english
        self.math = math

    def __repr__(self):
        return repr((self.name, self.native_lang, self.english, self.math))


num = int(sys.stdin.readline())

# make student object list
students = []

for _ in range(num):
    input_list = list(map(str, sys.stdin.readline().split()))
    stu_1 = Student(input_list[0], int(input_list[1]), int(input_list[2]), int(input_list[3]))
    students.append(stu_1)

students.sort(key=lambda x: (-x.native_lang, x.english, -x.math, x.name))

for i in students:
    print(i.name)

좋은 웹페이지 즐겨찾기