题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
利用双指针来做,
需要注意的是,在进行*的插入时会导致数组长度发生变化,因此不要使用for,而要使用while来控制数组的索引
s = input() str = list(s) i = 0 while i < len(str): if str[i].isdecimal(): str.insert(i, '*') j = i + 1 while j < len(str) and str[j].isdecimal(): j += 1 str.insert(j, '*') i = j i = i + 1 print(''.join(str))