题目描述
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
输入格式
一行字符,长度不超过200
样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
样例输出
23 16 2 4
题解一
#include<stdio.h>
int main()
{
int digit = 0,number = 0,blank = 0,others = 0,c;
while((c = getchar()) != '\n'){
if(c >= 'A' && c<='Z' || c >= 'a' && c <= 'z')
number++;
else if(c >= '0' && c <= '9')
digit++;
else if(c == ' ')
blank++;
else
others++;
}
printf("%d %d %d %d\n",number,digit,blank,others);
return 0;
}
题解二
#include<stdio.h>
#include<ctype.h>
int main()
{ int number=0,digit=0,blank=0,others=0,c;
while((c = getchar())!='\n'){
if (isalpha(c)) number++;
else if(isdigit(c)) digit++;
else if(isblank(c)) blank++;
else others++;
}
printf("%d %d %d %d",number,digit,blank,others);
return 0;
}