Problem Description
编写一个程序,统计各个数字、空白字符以及所有其它字符出现的次数。
Input Description
输入一个文本文件。处理到文件尾。
Output Description
按照输出样例格式输出所求结果。
Sample Input
13579 how are you!
24680 hello!
Sample Output
digit[0] = 1
digit[1] = 1
digit[2] = 1
digit[3] = 1
digit[4] = 1
digit[5] = 1
digit[6] = 1
digit[7] = 1
digit[8] = 1
digit[9] = 1
white = 6
other = 16
#include <stdio.h> int main() { int digit[10] = {0}; char ch; int white = 0, other = 0; while((ch = getchar()) != EOF) { if(ch <= '9' && ch >= '0') { ++digit[ch - '0']; } else if(ch == ' ' || ch == '\n' || ch == '\t') white++; else other++; } for(int i = 0; i <= 9; i++) printf("digit[%d] = %d\n", i, digit[i]); printf("white = %d\n", white); printf("other = %d\n", other); return 0; }