题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
// 方法一:不使用大小写转换方法
void (async function () {
const str = await readline();
const char = await readline();
let cnt = 0;
// 97 - 65 = 32
// 65 + 26 = 81
for(const c of str){
if(c === char || Math.abs(c.charCodeAt()- char.charCodeAt()) === 32 && Math.min(c.charCodeAt(), char.charCodeAt())>=65&& Math.min(c.charCodeAt(),char.charCodeAt())<=80) cnt ++
}
console.log(cnt);
})();
// 方法二:不使用大小写转换方法
void async function(){
const str = await readline();
const char = await readline();
let cnt = 0;
for(const c of str){
if(char.toLowerCase() === c.toLowerCase()) cnt++;
}
console.log(cnt);
}()

