题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <stdio.h> #include <string.h> int main() { char str[1000]; char ch1; char ch2; int count =0; int i=0; while( (ch1 = getchar()) != '\n') { str[i++] = ch1; } ch2 = getchar(); for(int i=0;i<strlen(str);i++) { if((ch2>=65) && (ch2<=90)) { if(str[i]==ch2+32) count++; } if((ch2>= 97) &&(ch2<=122)) { if(str[i]==ch2-32) count++; } if(str[i] == ch2) { count++; } } printf("%d\n",count); return 0; }