题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
s = input() # 两边扩展方便比较前后位置是否为数字 s = "#" + s + "#" out = "" # 输出结果从idx=1开始到idx=len(s)-2结束, 正好跳过首位# for idx in range(1, len(s) - 1): ch = s[idx] if (not "0" <= s[idx - 1] <= "9") and "0" <= ch <= "9" and (not "0" <= s[idx + 1] <= "9"): out += "*" + ch + "*" elif (not "0" <= s[idx-1] <= "9") and "0" <= ch <= "9": out += "*" + ch elif "0" <= ch <= "9" and (not "0" <= s[idx + 1] <= "9"): out += ch + "*" else: out += ch print(out)