题解 | #统计字符#
统计字符
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 tokens = line;
let result = new Array(4).fill(0);
result[0] = tokens.match(/[a-zA-Z]/g)
? tokens.match(/[a-zA-Z]/g).length
: 0;
result[1] = tokens.match(/[ ]/g) ? tokens.match(/[ ]/g).length : 0;
result[2] = tokens.match(/[0-9]/g) ? tokens.match(/[0-9]/g).length : 0;
result[3] = tokens.match(/[^0-9a-zA-Z ]/g)
? tokens.match(/[^0-9a-zA-Z ]/g).length
: 0;
result.forEach((item) => {
console.log(item);
});
}
})();