题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <stdio.h>
int main() {
int a = 0;
int b = 0;
int i = 0;
char target;
char str[1000];
int len;
scanf("%[^\n]\n", str); //读入第一行的所有数。
scanf("%c", &target);
len = strlen(str);
for (i = 0; i < len; i++) {
if ((str[i] - target) == 0) {
a++;
} else if (('Z' >= str[i]) && (str[i] >= 'A')) {
if ((target - str[i]) == 32) {
a++;
}
} else if (('z' >= str[i]) && (str[i] >= 'a')) {
if ((str[i] - target) == 32) {
a++;
}
}
}
printf("%d", a);
return 0;
}