题解 | #表示数字#

表示数字

https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    const str = await readline();
    let res = "";
    const isNumber = (char) => char>="0" && char <= "9";
    for(let i = 0; i < str.length-1; i++){
        res += str.charAt(i);
        if(isNumber(str.charAt(i))^isNumber(str.charAt(i+1))) res += "*";//字母数字拼接处插入"*"
    }
    res += str.charAt(str.length-1);
    if(isNumber(str.charAt(0))) res = "*" + res;//首字符是数字则在最前面插入"*"
    if(isNumber(str.charAt(str.length-1))) res += "*";//末字符是数字则在最后面插入"*"
    console.log(res);
}()

华为OD,我昵称“od400” 文章被收录于专栏

华为OD机试刷题历程,因涉及华为权益,牛客不允许更新了。我昵称“od400”,某博客继续更新。

全部评论

相关推荐

没有offer的呆呆:薪资有的时候也能说明一些问题,太少了活不活得下去是一方面,感觉学习也有限
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务