Love丶FFC's Blog

PAT乙级:1004 成绩排名

2020-01-26 22:02:56
阅读:1347   •   评论:15
标签:,

读入 n(>0)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

输入格式:

每个测试输入包含 1 个测试用例,格式为

第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
  ... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩

其中姓名学号均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

输出格式:

对每个测试用例输出 2 行,第 1 行是成绩最高学生的姓名和学号,第 2 行是成绩最低学生的姓名和学号,字符串间有 1 空格。

输入样例:

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

输出样例:

Mike CS991301
Joe Math990112

编程语言:Python

解题思想:

1.使用列表存储三个字段的值

2.对成绩进行判断并保留列表索引

时间复杂度:O(n)

代码如下:

  1. NOP = int(input())
  2. Student = [["Name", "ID", "Score"] for i in range(NOP)] # 创建姓名、学号、成绩的列表
  3. MaxScore, MinScore, MaxIndex, MinIndex = 0, 100, 0, 0 # 初始化最高成绩和最低成绩、最高成绩和最低成绩对应的学生在列表中的索引
  4. for i in range(NOP):
  5. Student[i] = list(map(str, input().split()))
  6. if int(Student[i][2]) > MaxScore: # 出现更高成绩
  7. MaxScore = int(Student[i][2])
  8. MaxIndex = i
  9. if int(Student[i][2]) < MinScore: # 出现更低成绩
  10. MinScore = int(Student[i][2])
  11. MinIndex = i
  12. print(Student[MaxIndex][0], Student[MaxIndex][1]) # 输出最高成绩学生姓名和学号
  13. print(Student[MinIndex][0], Student[MinIndex][1]) # 输出最低成绩学生姓名和学号

评论板

共有 15 条评论

  1. Jorcift

    cialis online reviews Such modifications include, for example, deletions from, and or insertions into and or substitutions of, residues within the amino acid sequences of the antibody

  2. cheap jordans for sale

    Read reviews and was a little hesitant since I had already inputted my order. as but thank god, I had no issues. just like received item in a timely matter, they are in new condition. regardless so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans for sale https://www.realcheapretrojordanshoes.com/

  3. louis vuitton outlet

    Read reviews and was a little hesitant since I had already inputted my order. or but thank god, I had no issues. particularly the received item in a timely matter, they are in new condition. anyway so happy I made the purchase. Will be definitely be purchasing again.
    louis vuitton outlet https://www.louisvuittonsoutletstore.com/

  4. cheap louis vuitton bags

    Read reviews and was a little hesitant since I had already inputted my order. or possibly a but thank god, I had no issues. for instance the received item in a timely matter, they are in new condition. either way so happy I made the purchase. Will be definitely be purchasing again.
    cheap louis vuitton bags https://www.louisvuittonsoutletonline.com/

  5. intuido

    buying generic cialis online safe This article was written by Kara Maxwell, MD, PhD

  6. intuido

    its close to the same type buy cialis online united states At first blush, it might seem that an increase in creatinine and BUN in the thiazide group might be a bad thing they re hurting the kidneys

  7. ESCVdf

    buy propecia 5mg Blood clots eg, deep vein thrombosis, pulmonary embolism or history of Should not be used in patients with this condition

  8. Yazfge

    order fenofibrate 200mg online cheap tricor pills order fenofibrate 200mg for sale

  9. Pfwquy

    tadalafil 40mg cheap buy viagra generic sildenafil overnight

  10. Wgnfap

    zaditor 1 mg brand buy ketotifen generic buy tofranil pills

  11. Ujyzov

    buy minoxidil without a prescription online ed meds buy generic ed pills over the counter

  12. Lkrvts

    buy precose for sale buy griseofulvin 250 mg without prescription order griseofulvin without prescription

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:503923