 
2019-01-22-PAT乙级-1004-成绩排名
原文链接:1001 害死人不偿命的(3n+1)猜想
github代码地址:HibisciDai/OJ-PAT-ACM
2019-01-22-PAT乙级-1004-成绩排名
编程描述
读入 n(>0)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。
辅助描述
| 12
 3
 4
 5
 
 | 作者: CHEN, Yue单位: 浙江大学
 时间限制: 400 ms
 内存限制: 64 MB
 代码长度限制: 16 KB
 
 | 
输入格式
每个测试输入包含 1 个测试用例,格式为
| 12
 3
 4
 5
 
 | 第 1 行:正整数 n第 2 行:第 1 个学生的姓名 学号 成绩
 第 3 行:第 2 个学生的姓名 学号 成绩
 ... ... ...
 第 n+1 行:第 n 个学生的姓名 学号 成绩
 
 | 
其中姓名和学号均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。
输出格式
对每个测试用例输出 2 行,第 1 行是成绩最高学生的姓名和学号,第 2 行是成绩最低学生的姓名和学号,字符串间有 1 空格。
输入样例
| 12
 3
 4
 
 | 3Joe Math990112 89
 Mike CS991301 100
 Mary EE990830 95
 
 | 
输出样例
| 12
 
 | Mike CS991301Joe Math990112
 
 | 
算法实现
JAVA(openjdk)
代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 
 | import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Scanner;
 
 public class Main {
 static class Student {
 String name;
 String num;
 int score;
 
 public Student(String name, String num, int score) {
 this.name = name;
 this.num = num;
 this.score = score;
 }
 
 @Override
 public String toString() {
 return name + " " + num;
 }
 
 }
 
 static class SortBySocre implements Comparator {
 public int compare(Object o1, Object o2) {
 Student s1 = (Student) o1;
 Student s2 = (Student) o2;
 if (s1.score > s2.score)
 return -1;
 return 1;
 }
 }
 
 public static Scanner sc = new Scanner(System.in);
 public static int total = 0;
 public static List<Student> alst = new ArrayList<Student>();
 
 public static void main(String[] args) {
 total = sc.nextInt();
 for (int i = 0; i < total; i++) {
 String a = sc.next();
 String b = sc.next();
 int c = sc.nextInt();
 Student s = new Student(a, b, c);
 alst.add(s);
 s.toString();
 }
 
 Collections.sort(alst, new SortBySocre());
 
 System.out.println(alst.get(0).toString());
 System.out.println(alst.get(total - 1).toString());
 }
 }
 
 | 
运行结果
| 12
 3
 4
 5
 6
 
 | 状态	分数	题目	编译器	耗时	用户答案正确	20	1004	Java (openjdk)	132 ms	HibisciDai
 测试点	结果	耗时	内存
 0	答案正确	116 ms	11824 KB
 1	答案正确	130 ms	11568 KB
 2	答案正确	132 ms	12088 KB
 
 | 
C
代码
运行结果