统计字符
运行时限: 1000 ms 单次运行时限: 1000 ms 内存限制: 32 MB
总提交: 400次 通过: 94次
题目描述
输入一行字符,分别统计出其中英文字母,空格、数字和其它字符的个数。
程序输入说明
一个字符串。(1 <= 长度 <= 1000)
程序输出说明
输出共四行,每行一个整数,分别表示字母个数,空格个数,数字个数,其它字符个数。
程序输入样例
可见格式 带空格和换行符的格式 带空格和换行符的格式说明
I love C progamming.
程序输出样例
Original Transformed 带空格和换行符的格式说明
16
3
0
1
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int alpha = 0,space = 0,number = 0,other = 0;
char c;
int i;
char str[1005];
gets(str);
for(i=0; str[i]; i++)
{
if(isalpha(str[i]))
alpha++;
else if(isdigit(str[i]))
number++;
else if(str[i] == ' ')
space++;
else
other++;
}
printf("%d\n%d\n%d\n%d\n",alpha,space,number,other);
return 0;
}
网友评论