题解 | #统计字符#

统计字符

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 a = 0;
            let b = 0;
            let c = 0;
            let d = 0;
        for (let i in line) {
            let n = line[i];
            if ((n >= "a" && n <= "z") || (n >= "a" && n <= "z")) {
                a++;
            } else if (n === " ") {
                b++;
            } else if (n >= "0" && n <= "9") {
                c++;
            } else {
                d++;
            }
        }
        console.log(a);
        console.log(b);
        console.log(c);
        console.log(d);
    }
})();

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务