题解 | #统计字符#

统计字符

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
    const str = await readline()
    let alphabetCount = 0
    let blanckCount = 0
    let numberCount = 0
    let other = 0
    for (let i=0; i<str.length; i++) {
        if(/[A-Za-z]/.test(str[i])) {
            alphabetCount++
        } else if(/\s/.test(str[i])) {
            blanckCount++
        } else if(/[0-9]/.test(str[i])) {
            numberCount++
        } else {
            other++
        }
    }
    console.log(alphabetCount)
    console.log(blanckCount)
    console.log(numberCount)
    console.log(other)

}() 

全部评论

相关推荐

07-02 10:44
门头沟学院 C++
码农索隆:太实诚了,告诉hr,你能实习至少6个月
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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