题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include "stdio.h" #include "string.h" #include "math.h" int main(){ char str[1000]={'0'}; char str_temp; int k = 0; int sum = 0; while((str[k++]=getchar())!='\n'); str_temp = getchar(); if((int)str_temp>=48&&(int)str_temp<=57){ for(k=0;str[k]!='\n';k++){ if(str[k]==str_temp){sum++;} } } else{ for(k=0;str[k]!='\n';k++){ if(abs((int)str[k] - (int)str_temp)==32||(int)str[k] == (int)str_temp){sum++;} } } printf("%d",sum); return 0; }