自己写的。C语言。getchar()。题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include<stdio.h> int main() { int c; int NumOfZiMu = 0, NumOfKongGe = 0, NumOfShuZi = 0, NumOfOther = 0; while ((c = getchar()) != 10) { if (c >= 'a' && c <= 'z') { NumOfZiMu++; } else if (c >= 'A' && c <= 'Z') { NumOfZiMu++; } else if (c == ' ') { NumOfKongGe++; } else if (c >= '0' && c <= '9') { NumOfShuZi++; } else { NumOfOther++; } } printf("%d\n%d\n%d\n%d\n", NumOfZiMu, NumOfKongGe, NumOfShuZi, NumOfOther); return 0; }