#include <stdio.h>
//统计各个数字、空白符(包括空格符、制表符、换行符)、以及其他所有字符的出现次数
int main(void){
int c;
int digit[10]={0};
int blank=0;
int other=0;
while((c=getchar())!=EOF){
if(c==' '||c=='\t'||c=='\n')
blank++;
else if(c>='0'&&c<='9')
digit[c-'0']++;//可以充当数组的合法下标
else
other++;
}
printf("空白符:%d\n",blank);
for(int i=0;i<10;i++)
printf("%d:%d\n",i,digit[i]);
printf("其他字符:%d\n",other);
}
统计各种字符的出现次数
最新推荐文章于 2023-05-06 22:28:18 发布