题解 | #字符串排序#

字符串排序

http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584

while True:
    try:
        s = input()
        a = ''
        for i in s:
            if i.isalpha(): # 先把是字母的部分都给挑选出来
                a += i
        b = sorted(a, key=str.upper) # 再对字母部分进行排序
        index = 0
        d = ''
        for i in range(len(s)):
            if s[i].isalpha(): # 如果原字符串中是字母的话,就用另外的字符替换
                d += b[index]
                index += 1
            else: # 其他字符串不需要作改变
                d += s[i]
        print(d)
    except:
        break
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务