题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <stdio.h> int main() { char* input = NULL; char ch; size_t inputSize = 0; int len = getline(&input, &inputSize, stdin); scanf("%c", &ch); if(ch >= 97){ ch -= 32; } char* pCur = input; int count = 0; while(pCur - input <= len){ if(*pCur == ch ){ ++count; } else if(*pCur - 32 == ch && *pCur >= 97){ ++count; } ++pCur; } printf("%d", count); return 0; }
感觉实现的有点复杂