题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

python3字典排序

思路

  • 用字典排序,分数为key 姓名为value
  • 考虑到会存在分数相同的同学,将姓名(append)保存到一个列表中
  • 将分数排序后,根绝列表从前往后打印value即可
    # 字典
    while True:
      try:
          dic = {}
          n = int(input())
          k = int(input())  
          for i in range(n):
              a,b = input().split()
              if int(b) in dic:
                  dic[int(b)].append(a)
              else:
                  dic[int(b)] = [a]
          if k == 0:
              res = sorted(dic,reverse=True)
              for i in res:
                  for j in range(len(dic[i])):
                      k = dic[i][j]
                      print(f'{k} {i}')
          else:
              res = sorted(dic)
              for i in res:
                  for j in range(len(dic[i])):
                      k = dic[i][j]
                      print(f'{k} {i}')
      except:
          break
    
    

```

全部评论

相关推荐

Jcwemz:中软证书写单行,考了什么学了什么相关技术栈的内容就说自己会什么, 没实习就包装实习简历,将项目经历写成实习做的,项目时间拉长,项目成果具体化,测试的项目成果无非就是写了多少用例查出了多少bug,重要的不是实习了多久,而是你会多少东西,你能表达的就都是你的。 cet4,随便找个地方标上就好了,不用写单行。 粗略建议,我也不在行,觉得对的可以采纳
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务