统计字符
来源:互联网 发布:无锡招聘淘宝模特 编辑:程序博客网 时间:2024/06/03 17:57
题目描述
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
输入
一行字符
输出
统计值
样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
样例输出
23 16 2 4
#include <stdio.h>
#include <stdlib.h>
int main()
{
int letter=0,number=0,space=0,others=0,ch;
ch=getchar();
while(ch!='\n')
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
letter++;
else if(ch>='0'&&ch<='9')
number++;
else if(ch==' ')
space++;
else
{
others++;
}
ch=getchar();
}
printf("%d %d %d %d\n",letter,number,space,others);
return 0;
}
0 0