题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) val n = read.nextLine().toInt() val low = read.nextLine().toInt() == 1 val map = mutableMapOf<Int, String>() val array = Array(n) { Array(2) { 0 } } for (i in 0 until n) { val pair = read.nextLine() map[i] = pair array[i][0] = i array[i][1] = pair.split(' ')[1].toInt() } array.sortWith { o1, o2 -> if (low) o1[1] - o2[1] else o2[1] - o1[1] } array.forEach { println("${map[it[0]]}") } }