题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
用两个while循环来解决连续数字的问题
while True: try: st=input() a,i=[],0 while i<len(st): if st[i].isdigit():#首先判断字符是否为数字 a.append("*")#如果是数字,则在a尾部添加“*”,注意此时数字还没插入 while i<len(st) and st[i].isdigit():#判断是是否是连续数字 a.append(st[i])#向链表a里插入连续数字 i+=1 a.append("*")#循环结束,说明此时st[i]不是数字,添加“*” else: a.append(st[i]) i+=1 print("".join(a)) except: break