题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
while True:
try:
a = input()
b = input()
c = {}
e = []
for i in range(int(a)):
d = input().split(' ')
if d[1] not in c.keys():
c[d[1]] = d[0]
else:
c[d[1]] = c[d[1]] + ' ' + d[0]
for i in c.keys():
e.append(int(i))
e.sort()
if int(b):
for i in e:
if ' ' not in c[str(i)]:
print(c[str(i)]+' '+str(i))
else:
for j in c[str(i)].split(' '):
print(j+' '+str(i))
else:
for i in e[::-1]:
if ' ' not in c[str(i)]:
print(c[str(i)]+' '+str(i))
else:
for j in c[str(i)].split(' '):
print(j+' '+str(i))
except:
break
腾讯云智研发成长空间 241人发布