import java.util.Scanner; import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = Integer.valueOf(in.next()); int flag = Integer.valueOf(in.next()); Student[] students = new Student[n]; for (int i = 0; i < n; i++) { students[i] = new Student(in.next(), Integer.valueOf(in.next())); } Arrays.sort(students, (v, w) -> { if (flag == 0) { return w.grade - v.grade; } else { return v.grade - w.grade; } }); Arrays.stream(students).forEach(stu -> System.out.println(stu.name + " " + stu.grade)); } } } class Student { public int grade; public String name; public Student(String name, int grade) { this.name = name; this.grade = grade; } public String toString() { return name + " " + grade; } }
点赞

相关推荐

10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
牛客网
牛客企业服务