python3 把该插入的位置找到保存到add_index中,然后遍历插入即可
表示数字
http://www.nowcoder.com/questionTerminal/637062df51674de8ba464e792d1a0ac6
while True: try: s = input() res = list(s) add_index = [] for i in range(len(s)): if i == 0: if s[i].isdigit(): add_index.append(i) continue elif not s[i].isdigit() and s[i-1].isdigit(): add_index.append(i) elif s[i].isdigit() and not s[i-1].isdigit(): add_index.append(i) for i in range(len(add_index)): res.insert(add_index[i]+i, '*') if res[-1].isdigit(): res.append('*') print(''.join(res)) except: break