题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <stdio.h> int main() { char str[5000]; char c; int i = 0; int count = 0; gets(str); c = getchar(); if ( c >= 'a' && c <= 'z' ) { while (str[i] != '\0') { if (str[i] == c || str[i] == (c - 'a' + 'A')) { count++; } i++; } } else if (c >= 'A' && c <= 'Z') { while (str[i] != '\0') { if (str[i] == c || str[i] == (c - 'A' + 'a')) { count++; } i++; } } else { while (str[i] != '\0') { if (str[i] == c) { count++; } i++; } } printf("%d", count); return 0; }