题解 | #表示数字#

表示数字

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

#print(ord('A'),ord('0'))
'''
s=list(input())
s1=''
pre_s=''
for i in s:
    if i.isdigit():
        if pre_s.isdigit()==0:
            s1 += '*'
    else:
        if pre_s.isdigit():
            s1 += '*'
    s1 += i
    pre_s = i
if s[-1].isdigit():
    s1 += '*'

print(s1)
''' '''
while True:
    try:
        s = input()
        sn = ''
        s = s.replace('*', '&')
        for i in s:
            if i.isdigit():
                sn += '*' + i + '*'
            else:
                sn += i
        sn = sn.replace('**', '')
        print(sn.replace('&', '*'))
    except:
        break
'''

import re
while True:
    try:
        print(re.sub('(\d+)', '*\g<1>*', input()))
        ''' re.sub(目标字段i,新字段j,所在字符串s) 将s中的i替换为j
            \d 任意0-9数字
            + 匹配+前面一次或多次   \d+ 一个数字或多个数字
            \g<1> sub()的group替换,指代前组的第1个字段 \g<1>\g<2>\g<3>
        '''
    except:
        break

全部评论

相关推荐

10-22 12:03
山东大学 Java
程序员小白条:26届一般都得有实习,项目可以随便写的,如果不是开源社区的项目,随便包装,技术栈也是一样,所以本质应该找学历厂,多投投央国企和银行,技术要求稍微低一点的,或者国企控股那种,纯互联网一般都得要干活
应届生简历当中,HR最关...
点赞 评论 收藏
分享
孙艹肘:校招不给三方直接让实习我都去了,,主打一个在学校呆着也是闲着,不如出来实习一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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