题解 | #成绩排序#
成绩排序
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); // 注意 hasNext 和 hasNextLine 的区别 int a = in.nextInt(); int b = in.nextInt(); LinkedList<String> [] arr = new LinkedList [101]; for (int i = 0 ; i < a ; i++) { String str = in.next(); int index = in.nextInt(); if (arr[index] == null) { arr[index] = new LinkedList(); } arr[index].add(str); } if (b == 0) { for (int i = 100 ; i >= 0 ; i--) { if (arr[i] != null) { for (String st : arr[i]) { System.out.println(st + " " + i); } } } } else { for (int i = 0 ; i <= 100 ; i++) { if (arr[i] != null) { for (String st : arr[i]) { System.out.println(st + " " + i); } } } } } }