题解 | #成绩排序#
成绩排序
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);
int n = Integer.valueOf(in.nextLine());
int sort = Integer.valueOf(in.nextLine());
List<String> strings = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
strings.add(in.nextLine());
}
Collections.sort(strings, (a, b) -> {
int i = Integer.valueOf(a.split(" ")[1]).compareTo(Integer.valueOf(b.split(" ")[1]));
return sort == 1 ? i : -i;
});
for (String s : strings) {
System.out.println(s);
}
}
}
#java一个集合搞定#