用户登录
用户注册

分享至

成绩排名

  • 作者: 蒙奇迪孤狼
  • 来源: 51数据库
  • 2021-11-22

描述

已有a、b两个链表,每个链表中的结点包括学好、成绩。要求把两个链表合并,按学号升序排列。

输入

第一行,a、b两个链表元素的数量N、M,用空格隔开。 接下来N行是a的数据 然后M行是b的数据 每行数据由学号和成绩两部分组成

输出

按照学号升序排列的数据

输入样例 1

2 3
5 100
6 89
3 82
4 95
2 10

输出样例 1

2 10
3 82
4 95
5 100
6 89

Python

import operator


class Student:
    def __init__(self, pid, score):
        self.pid = pid
        self.score = score


Nodes = []
a, b = map(int, input().split())
for i in range(a + b):
    pid, score = map(int, input().split())
    student = Student(pid, score)
    Nodes.append(student)

cmp = operator.attrgetter('pid', 'score')
Nodes.sort(key=cmp)
for student in Nodes:
    print(student.pid, student.score)
软件
前端设计
程序设计
Java相关