AcWing 429. Java自定义比较器,10几行写法
原题链接
简单
作者:
zlnnjit
,
2021-02-02 21:35:05
,
所有人可见
,
阅读 409
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//info[n]:{学号,总成绩,语文}
int info[][] = new int[n][3];
for (int i = 0; i < info.length; i++) {
int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
info[i] = new int[]{i + 1, a + b + c, a};
}
Arrays.sort(info, (o1, o2) -> o1[1] == o2[1] ? (o1[2] == o2[2] ? o1[0] - o2[0] : o2[2] - o1[2]) : o2[1] - o1[1]);
for (int i = 0; i < 5; i++) System.out.println(info[i][0] + " " + info[i][1]);
}
}