题目描述
从键盘输入一行字符(长度小于等于1000),统计出其中的英文字母、数字、空格、和其它字符的个数。
输入要求
输入一行字符(长度小于等于1000)。
输出要求
按字母、数字、空格、其它字符的顺序输出各类字符的统计结果。为0的项目也要输出。用空格隔开(最后一个数字的后面无空格)。
输入样例
Hello Boy. It is 30 July.
输出样例
16 2 5 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
int len1=0,len2=0,len3=0,len4=0;
ch=getchar();
while(ch!='\n')
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
len1=len1+1;
}
else if(ch>='0'&&ch<='9')
{
len2+=1;
}
else if(ch==' ')
{
len3+=1;
}
else
{
len4+=1;
}
ch=getchar();
}
printf("%d %d %d %d\n",len1,len2,len3,len4);
return 0;
}