题目描述:
输入一行字符,以回车符作为输入结束的标志。回车符不作为有效字符。有效字符个数不超过100。统计其中英文字母、数字字符和其他字符的个数。
时间限制 :
1.000 sec 内存限制 : 128 MB
样例:
输入:Abse 4+5*3=?
输出:letter:4
digit:3
other:5
注意:
1.在ASCLL表上,大写字母和小写字母并不相邻,判断时无法写成ch[i]>='A' and ch[i]<='z';
2.letter、digit、other定义时要给他们初始化,否则结果未知。
#include<stdio.h>
int main()
{
char ch[100];
int i=0,letter=0,digit=0,other=0;
for(i;;i++)
{
scanf("%c",&ch[i]);
if(ch[i]=='\n')
break;
else
{
if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z'))//判断是不是字母
letter++;
else
{
if(ch[i]>='0'&&ch[i]<='9')//是不是数字
digit++;
else
other++; //其他字符
}
}
}
printf("letter:%d\n",letter);//依次输出,每个一行
printf("digit:%d\n",digit);
printf("other:%d\n",other);
return 0;
}