Python题解 | #表示数字#

表示数字

https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6

import sys


while True:
    try:
        s = input().strip()
        res = ''
        i = 0
        while i < len(s):
            if not s[i].isdigit():
                res += s[i]
            else:
                res += '*'
                res += s[i]
                j = i + 1

                while j < len(s):
                    if s[j].isdigit():
                        res += s[j]
                        j += 1
                    else:
                        res += '*'
                        i = j
                        res += s[j]
                        break
                if j == len(s):
                    res += '*'
                    break
            i += 1
        print(res)

    except:
        break

全部评论
注意判断最后一位是数字的特殊情况
点赞
送花
回复 分享
发布于 05-18 21:43 上海

相关推荐

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