问题描述:输入一行字符,分别统计出其中英文字母,数字,空格和其他字符的个数。
文件名:the_ninth_week_OJ1032
作者:何知令
发表时间:2016年10月30日
输入:一行包含任意字符的字符串
输出:其中各类字符的个数
代码如下:
#include <stdio.h>
int main()
{
int English,math,space,others,i;
char c;
English=0;
math=0;
space=0;
others=0;
i=0;
while((c=getchar())!='\n')
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
English=English+1;
}
else if(c>='0'&&c<='9')
{
math=math+1;
}
else if(c==' ')
{
space=space+1;
}
else
{
others=others+1;
}
i++;
}
printf("%d %d %d %d",English,math,space,others);
return 0;
}
程序运行结果展示:
知识点总结:多组字符输入并分类计算个数
学习心得:记住“=”与“==”的区别!