题解 | 单词倒排

单词倒排

https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

import sys
import string
all_chr = string.ascii_letters
for line in sys.stdin:
    a = line.split("\n")[0]
    temp = ""
    for _ in a:
        if _ in all_chr:
            temp += _
        else:
            temp += ' '
    temps = temp.split(" ")
    #print(temps)
    for i in range(len(temps)-1,-1,-1):
        print(temps[i],end=' ')

根据字符集分割字符串,然后再倒着输出一遍就行

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务