题解 | #字母统计#
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <stdio.h> #include <string.h> int main(){ char arr[100]; //输入的最大长度 scanf("%s", arr); int len = strlen(arr); int num; int count[91] = {0}; //只有65-90有用 for (int i = 65; i <= 90; ++i) { //A-Z对应为65-90 for (int j = 0; j < len; ++j) { num = arr[j]; //把字符转化为对应的ASCII码 if (num == i){ count[i]++; } } } for (int i = 65; i <= 90; ++i) { printf("%c:%d\n", i, count[i]); } return 0; }