题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <math.h> #include <stdio.h> #include <string.h> int main() { char a[1000], b; int n = 0; gets(a); //printf("a=%s\n", a); scanf("%c", &b); //printf("b=%c\n", b); if(b >= 'A' && b <= 'Z') b = b - 'A' + 'a'; for (int i =0; i < strlen(a); i++) { if ((b == a[i]) || (b == a[i] - 'A' + 'a')) { n++; } } printf("%d\n",n); return 0; }