解题思路:
注意事项:
参考代码:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class Stu{
int id;
int chinese;
int math;
int english;
int sum;
public Stu(int id,int chinese,int math,int english) {
this.id = id;
this.chinese = chinese;
this.math = math;
this.english = english;
this.sum = chinese + math + english;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Stu[] students = new Stu[n];
for (int i = 0; i < n; i++) {
students[i] = new Stu(i + 1, scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
}
Arrays.sort(students,new Comparator<Stu>() {
@Override
public int compare(Stu stu1,Stu stu2) {
if (stu1.sum == stu2.sum ) {
if (stu1.chinese == stu2.chinese) {
return stu1.id - stu2.id;
}
else {
return stu2.chinese - stu1.chinese;
}
}
return stu2.sum - stu1.sum;
}
});
for (int i = 0; i < 5; i++) {
System.out.println(students[i].id + " " + students[i].sum);
}
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:1175 |
简单的a+b (C语言代码)浏览:685 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:634 |
WU-格式化数据输出 (C++代码)浏览:1312 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:606 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:934 |
【蟠桃记】 (C语言代码)浏览:1084 |
母牛的故事 (C语言代码)浏览:1451 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:490 |