题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) val res = read.nextLine() val words = res.split(' ') when(words.size) { 0 -> print(res) else -> { for (i in words.lastIndex downTo 1) { print("${words[i]} ") } print(words[0]) } } }