题解 | 字符串排序

字符串排序

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

s = input()
letters = [c for c in s if c.isalpha()]
sorted_l = sorted(letters,key=str.lower)
cnt = 0
res = ""
for i in range(0,len(s)):
    c = s[i]
    if c.isalpha():
        res = res + sorted_l[cnt]
        cnt = cnt + 1
    else:
        res = res + c
print(res)

全部评论

相关推荐

Clavoss:一眼AI,死亏
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
09-04 11:44
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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