python64分求助!!

P1104 生日

lizirui2002 @ 2024-03-05 20:03:50

代码如下 思路是先定义一个类存储输入的每个人的信息,id就相当于输入的先后.然后用lambda表达式和内置的sorted方法依次比较年月日输入次序对全都是对象的列表排序,但是总是64分,求大家教教qwq

n=int(input())
class people:
    def __init__(self,name,year,month,day,id):
        self.name=name
        self.year=year
        self.month = month
        self.day = day
        self.id=id
people_list = []
for i in range(0,n):
    name,year,month,day = input().split()
    real_year = int(year)
    real_month = int(month)
    real_day = int(day)
    people_list.append(people(name,real_year,real_month,real_day,i))

first_sort=sorted(people_list,key=lambda obj:(obj.year,obj.month,obj.day,obj.id))
for i in first_sort:
    print(f'{i.name}\r')

by llly_ya @ 2024-03-11 17:25:46

id大的先输出,应该改为 first_sort=sorted(people_list,key=lambda obj:(obj.year,obj.month,obj.day,-obj.id))


|