题解 | #统计字符#
统计字符
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)
}()
查看7道真题和解析