本题要求编写程序,输入一行字符,统计其中数字字符、空格和其他字符的个数。建议使用switch语句编写。
输入格式:
输入在一行中给出若干字符,最后一个回车表示输入结束,不算在内。
输出格式:
在一行内按照
blank = 空格个数, digit = 数字字符个数, other = 其他字符个数
的格式输出。请注意,等号的左右各有一个空格,逗号后有一个空格。
输入样例:
在这里给出一组输入。例如:
Reold 12 or 45T
结尾无空行
输出样例:
在这里给出相应的输出。例如:
blank = 3, digit = 4, other = 8
#include <stdio.h>
int 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')
{
other++;
}
else if (c == ' ')
{
space++;
}
else if (c >= '0'&&c <= '9')
{
digit++;
}
else
{
other++;
}
}
printf("blank = %d, digit = %d, other = %d",space,digit,other);
return 0;
}