PAT乙级-1015 德才论
解题代码(部分运行超时):
##输入 admission_list = list(map(int,input().rstrip().split())) allstudent_list =[] for i in range(admission_list[0]): allstudent_list.append(list(map(int,input().rstrip().split()))) ##分类 #优先录取 beststu_list = [] #德胜才 twostu_list = [] #德才兼亡 threestu_list = [] #过线 fourstu_list = [] #真正第四类 truefoustu_list = [] for i in range(len(allstudent_list)): if allstudent_list[i][1] >= admission_list[1] and allstudent_list[i][2] >= admission_list[1]: fourstu_list.append(allstudent_list[i]) admission_len = len(fourstu_list) for i in range(len(fourstu_list)): if fourstu_list[i][1] >= admission_list[2] and fourstu_list[i][2] >= admission_list[2]: beststu_list.append(fourstu_list[i]) elif fourstu_list[i][1] >= admission_list[2] and fourstu_list[i][2] < admission_list[2]: twostu_list.append(fourstu_list[i]) elif fourstu_list[i][1] < admission_list[2] and fourstu_list[i][2] < admission_list[2] and fourstu_list[i][1] >= fourstu_list[i][2]: threestu_list.append(fourstu_list[i]) else: truefoustu_list.append(fourstu_list[i]) def sortstu(stu_list): for i in range(len(stu_list)): for j in range(0,len(stu_list)-i-1): if stu_list[j][1] + stu_list[j][2] < stu_list[j+1][1] + stu_list[j+1][2]: stu_list[j],stu_list[j+1] = stu_list[j+1],stu_list[j] elif stu_list[j][1] + stu_list[j][2] == stu_list[j+1][1] + stu_list[j+1][2] and stu_list[j][1] < stu_list[j+1][1]: stu_list[j],stu_list[j+1] = stu_list[j+1],stu_list[j] elif stu_list[j][1] + stu_list[j][2] == stu_list[j+1][1] + stu_list[j+1][2] and stu_list[j][1] == stu_list[j+1][1] and stu_list[j][0] > stu_list[j+1][0]: stu_list[j],stu_list[j+1] = stu_list[j+1],stu_list[j] if len(beststu_list) > 1: sortstu(beststu_list) if len(twostu_list) > 1: sortstu(twostu_list) if len(threestu_list) > 1: sortstu(threestu_list) if len(truefoustu_list) > 1: sortstu(truefoustu_list) all_student = beststu_list + twostu_list + threestu_list + truefoustu_list print(admission_len) for i in all_student: for j in range(len(i)): if j == len(i) - 1: print(i[j]) else: print(i[j],end = ' ')