题目
描述
写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字符,然后输出输入字符串中该字符的出现次数。(不区分大小写字母)
数据范围:
1≤n≤1000
输入描述:
第一行输入一个由字母、数字和空格组成的字符串,第二行输入一个字符(保证该字符不为空格)。
输出描述:
输出输入字符串中含有该字符的个数。(不区分大小写字母)
示例1
输入: ABCabc
A
输出: 2
代码
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 ((a = await readline())) {
b = await readline();
a = a.toLowerCase();
b = b.toLowerCase();
let count = 0;
for (let index = 0; index < a.length; index++) {
if (a.slice(index, index + 1) === b) {
count++;
}
}
console.log(count);
}
})();