题目链接:奖学金
java代码:
import java.util.Arrays;
import java.util.Scanner;
class Student implements Comparable<Student>{
int chinese;
int math;
int english;
int sum;
int id;
public Student(int chinese, int math, int english, int id) {
super();
this.chinese = chinese;
this.math = math;
this.english = english;
this.id = id;
this.sum = chinese + math + english;
}
public int compareTo(Student newStudent) {
if(this.sum!=newStudent.sum)
return Integer.compare(newStudent.sum, this.sum);
else if(this.chinese!=newStudent.chinese)
return Integer.compare(newStudent.chinese, this.chinese);
else
return Integer.compare(this.id, newStudent.id);
}
}
public class Main {
public static void main(String[] args) {
int n;
Scanner in = new Scanner(System.in);
n = in.nextInt();
Student arr[] = new Student[n];
for(int i=0;i<n;++i)
arr[i]= new Student(in.nextInt(),in.nextInt(),in.nextInt(),i+1);
Arrays.sort(arr);
for(int i=0;i<5;++i)
System.out.println(arr[i].id + " " +arr[i].sum);
}
}