烟台大学计算机与控制工程学院
All rights reserved.
作者:汪莹莉
完成时间:2016年10月30日
题目描述:
输入一行字符,分别统计出其中的英文字母、数字、空格和其他字符的个数
sample input:
aklsjflj123 sadf91u32oasdf/.' ;123
sample output
23 16 3 4
/*
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
int n=0,i=0,m=0,b=0;
while((c=getchar())!='\n')
{
if ((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
n++;
else if(c>='0'&&c<='9')
i++;
else if(c==' ')
b++;
else
m++;
}
printf("%d %d %d %d\n",n,i,b,m);
return 0;
}
运行结果:
知识点总结:了解到各个字母及数字的·ASCII值,A:65 a:97 空格:32
学习心得:字符变量;char c;while((c=getchar())!='\n')表示逐步输入