简单排序(类)
import java.io.IOException; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); Stack<Character> st = new Stack<Character>(); int n = sc.nextInt(); Student[] stu = new Student[n]; for(int i = 0;i < n;i++){ stu[i] = new Student(); stu[i].chinese = sc.nextInt(); stu[i].sum = stu[i].chinese + sc.nextInt() + sc.nextInt(); stu[i].id = i + 1; } Arrays.sort(stu); for(int i = 0;i < 5;i++){ System.out.printf(stu[i].id +" "+ stu[i].sum); System.out.println(); } } } class Student implements Comparable<Student>{ int chinese,math,english,sum; int id; public int compareTo(Student o){ if(this.sum != o.sum){ return ((int) (o.sum - this.sum)); }else { if(o.chinese != this.chinese){ return ((int)(o.chinese - this.chinese)); }else { return this.id - o.id; } } } }