题解 | #字母统计#
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <stdio.h> // 计算字符串长度: int Length(char a[]) { int n = 0; for (int i = 0; a[i] != '\0'; i++) { n++; } return n; } typedef struct { char a; int b; } Letter; int main() { char a[100] = ""; scanf("%s", a); Letter T[26]; T[0].a = 'A'; T[0].b = 0; for (int i = 1; i < 26; i++) { T[i].a = (T[i - 1].a) + 1; T[i].b = 0; } int len = Length(a); for (int j = 0; j < len; j++) { int number = 0; if (a[j] >= 60 && a[j] <= 90) { number = a[j] - 'A'; T[number].b++; } } for (int k = 0; k < 26; k++) { printf("%c:%d\n", T[k].a, T[k].b); } return 0; }