题解 | #统计字符#
统计字符
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 = [0, 0, 0, 0]
//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])
}
}()