题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5


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

void async function () {
    // Write your code here
    while (line = await readline()) {
        let re1 = /[a-zA-Z]/g
        let re2 = /[0-9]/g
        let re3 = /[^0-9a-zA-Z]/g
        let res = [0000]
        //1
        if (re1.test(line)) {
            res[0] = line.match(re1).length
        }
        if (line.includes(" ")) {
            //2
            res[1] = line.split(" ").length - 1
        }
        if (re2.test(line)) {
            //3
            res[2] = line.match(re2).length
        }
        if (re3.test(line)) {
            //4
            res[3] = line.match(re3).length - res[1]
        }

        console.log(res[0])
        console.log(res[1])
        console.log(res[2])
        console.log(res[3])
    }
}()

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 10:39
一个证都没 我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
Lorn的意义:你这标个前端是想找全栈吗?而且项目确实没什么含金量,技术栈太少了,边沉淀边找吧 现在学院本想就业好一点四年至少得高三模式两年加油吧
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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