题解 | #表示数字#

表示数字

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

import re

text = input()
num = []
word = []
s = ""
for i in re.split("[^0-9]", text):
    if len(i) != 0:
        num.append(i)
for i in re.split("[0-9]", text):
    if len(i) != 0:
        word.append(i)

if text.isnumeric():
    s = "*" + text + "*"
elif text.isalpha() and not text.isnumeric():
    s = text
else:
    for i in range(min(len(num), len(word))):
        if text[0].isnumeric():
            s = s + "*" + num[i] + "*" + word[i]
        else:
            s = s + word[i] + "*" + num[i] + "*"

    if len(word) > len(num):
        s = s + word[-1]
    elif len(num) > len(word):
        s = s + "*" + num[-1] + "*"
print(s)

全部评论

相关推荐

谁知道呢_:你好,我是炮灰n+1号
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务