题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include <stdio.h> int main() { char asciiArray[37] = {0}; char input; while (scanf("%c", &input)) { if (input == '\n') break; else if (input == ' ') continue; else if (input <= '9') asciiArray[input - '0'] ++; else if (input <= 'Z') asciiArray[input - 'A' + 10] ++; else // case: input <= 'z' asciiArray[input - 'a' + 10] ++; } scanf("%c", &input); int retval; if (input <= '9') retval = asciiArray[input - '0']; else if (input <= 'Z') retval = asciiArray[input - 'A' + 10]; else retval = asciiArray[input - 'a' + 10]; printf("%d", retval); }