题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
s = input()
res = ''
flag = False # 开关
for c in s:
if c.isdigit() and flag == False: # 数字子串开头
flag = not flag
res += '*'
res += c
elif c.isdigit() and flag == True: # 数字子串过程
res += c
elif not c.isdigit() and flag == True: # 数字子串结尾
flag = not flag
res += '*'
res += c
else:
res += c
# 如果最后一位是数字,补全一个*
if s[-1].isdigit():
res += '*'
print(res)
查看11道真题和解析