题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on('line', function (line: string) { let start = -1; let end = line.length; for (let i = 0; i < line.length; i++) { if (/[0-9]/.test(line[i])) { if (start === -1) { start = i; } } else if (start !== -1) { end = i; const str = line.substring(start, end); line = line.substring(0, start) + `*${str}*` + line.substring(end); start = -1; end = line.length; i = i + 2; } } if (start !== -1 && end === line.length) { const str = line.substring(start, end); line = line.substring(0, start) + `*${str}*` + line.substring(end); } console.log(line); });