题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { int size = Integer.parseInt(in.nextLine()); int order = Integer.parseInt(in.nextLine()); List<String[]> list = new ArrayList<>(); for (int i = 0; i < size; i++) { String[] split = in.nextLine().split(" "); list.add(split); } list.sort((o1, o2) -> { if (order == 1) return Integer.parseInt(o1[1]) - Integer.parseInt(o2[1]); else return Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]); }); for (String[] strings : list) { System.out.println(strings[0] + " " + strings[1]); } } } }