Description
输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
Input
一行字符
Output
统计值
Sample Input
aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123
Sample Output
23 16 2 4
#include<stdio.h>
main()
{
char c;
int letters=0,space=0,digit=0,other=0;
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
{
letters++;
}
else if(c==' ')
{
space++;
}
else if(c>='0'&&c<='9')
{
digit++;
}
else
{
other++;
}
}
printf("%d %d %d %d",letters,digit,space,other);
}
版权声明:本文为qq_41963221原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。