题解#输入整型数组和排序标识对其元素按照升序或降序进行排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) while (read.hasNextLine()) { read.nextLine() val b = read.nextLine().split(" ").map { it.toInt() } val c = read.nextLine().toInt() val a = b.sortedWith(if (c == 0) { compareBy { it } } else compareByDescending { it } ) println(a.joinToString(" ")) } }
HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序
#kotlin#