题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
import java.util.Scanner fun main(args: Array<String>) { fun Char.lowercase():String = Character.toLowerCase(this).toString() val read = Scanner(System.`in`) val res = read.nextLine() var list = mutableListOf<Char>() res.forEach { if (it.isLetter()) { list.add(it) } } val list1 = list.sortedWith { c: Char, c1: Char -> c.lowercase().compareTo(c1.lowercase()) } var n = 0 res.forEach{ if (it.isLetter()) { print(list1[n++]) } else { print(it) } } }