问题及代码
/*
烟台大学计算机学院 2016
作者: 马春澎
完成日期:2016年10月30日
问题描述:
Description
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
Input
一行字符
Output
统计值
Sample Input
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
Sample Output
23 16 2 4
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
int word=0,number=0,space=0,other=0;
while((c=getchar())!='\n')
{
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
word++;
}
else if(c>='0'&&c<='9')
{
number++;
}
else if(c==' ')
{
space++;
}
else other++;
}
printf("%d %d %d %d\n",word,number,space,other);
return 0;
}
运行结果
知识点总结
考察C语言中字符的应用
学习心得
要清楚的表达出每个字母所代表的含义,要使用规范,让读者可以看明白。