题解 | #句子逆序#

句子逆序

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])
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务