题解 | #成绩排序#
成绩排序
http://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
import sys getline=lambda:sys.stdin.readline().strip() n=getline() sign=getline() line=getline() def func(elm): return elm[1] while line: # d={} result=[] # d[line.split(" ")[0]]=int(line.split(" ")[1]) result.append([line.split(" ")[0],int(line.split(" ")[1])]) for i in range(int(n)-1): line=getline() # d[line.split(" ")[0]]=int(line.split(" ")[1]) result.append([line.split(" ")[0],int(line.split(" ")[1])]) if sign=='0': # for k in sorted(d,key=d.__getitem__,reverse=True): # print(k,d[k]) for i in sorted(result,key=func,reverse=True): for x in i: print(x,end=" ") print() else: # for k in sorted(d,key=d.__getitem__): # print(k,d[k]) for i in sorted(result,key=func): for x in i: print(x,end=" ") print() n=getline() sign=getline() line=getline()