C语言:编写一个程序,统计输入正文中每个数字字符,英文字符和其他字符出现的次数
编写一个程序,统计输入正文中每个数字字符,英文字符和其他字符出现的次数(要求用数组元素作为每个数字字符、英文字符、和其他字符出现的次数的计数器)。输入:一段文字,以EOF...
编写一个程序,统计输入正文中每个数字字符,英文字符和其他字符出现的次数(要求用数组元素作为每个数字字符、英文字符、和其他字符出现的次数的计数器)。
输入:一段文字,以EOF结束(Crtl+Z)
输出:参照样例输出。
样例输入
"123 The day the child realizes that all adults are imperfect 456456,
he becomes an adolescent; 345 the day he forgives them, he becomes an adult; the day he forgives himself, he becomes wise." 342
样例输出
Number 0: 0
Number 1: 1
Number 2: 2
Number 3: 3
Number 4: 4
Number 5: 3
Number 6: 2
Number 7: 0
Number 8: 0
Number 9: 0
characters: 140
other: 44 展开
输入:一段文字,以EOF结束(Crtl+Z)
输出:参照样例输出。
样例输入
"123 The day the child realizes that all adults are imperfect 456456,
he becomes an adolescent; 345 the day he forgives them, he becomes an adult; the day he forgives himself, he becomes wise." 342
样例输出
Number 0: 0
Number 1: 1
Number 2: 2
Number 3: 3
Number 4: 4
Number 5: 3
Number 6: 2
Number 7: 0
Number 8: 0
Number 9: 0
characters: 140
other: 44 展开
1个回答
展开全部
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
int main(void){
char ch;
int Dec[10]={0},letter=0,other=0,i=0;
while(1){
if((ch=getchar())>='0' && ch<='9')
Dec[ch-'0']++;
else if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')
letter++;
else if(ch=='\n')
break;
else other++;
}
for(i=0;i<10;printf("Number%d: %d\n",i,Dec[i++]));
printf("Characters: %d\n",letter);
printf("Other: %d\n",other+1);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询