题解 | #表示数字#

表示数字

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”,某博客继续更新。

全部评论

相关推荐

09-05 21:54
已编辑
湖南工程学院 Java
点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务