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