题解 | #字符串排序#

字符串排序

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

Note new functions:

  • isalpha(): determine whether all English characters
  • sorted(xxx, key = str.upper): sort by uppercase
while True:
    try:
        ipt = input()
        # 1. sort out all characters
        a = ''
        for i in ipt:
            # add to new string only if it is an English character
            if i.isalpha():
                a += i
        b = sorted(a, key = str.upper)
        # 2. add other non-characters
        index = 0
        c = ''
        for i in range(0, len(ipt)):
            if ipt[i].isalpha():
                c += b[index]
                index += 1
            else:
                c += ipt[i]
        print(c)
    except:
        break
全部评论

相关推荐

ArisRobert:统一解释一下,第4点的意思是,公司按需通知员工,没被通知到的员工是没法去上班的,所以只要没被通知到,就自动离职。就是一种比较抽象的裁员。
点赞 评论 收藏
分享
评论
2
收藏
分享
牛客网
牛客企业服务