题目描述
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
输入格式
一行字符,长度不超过200
输出格式
统计值
样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
样例输出
23 16 2 4
#include<stdio.h>
#include<ctype.h>
int main(){
char ch;
int alp_num=0,digit_num=0,blank_num=0,other_num=0;
while((ch=getchar())!='\n'){
if(isalpha(ch)){
alp_num++;
}else if(isdigit(ch)){
digit_num++;
}else if(isblank(ch)){
blank_num++;
}else{
other_num++;
}
}
printf("%d %d %d %d",alp_num,digit_num,blank_num,other_num);
return 0;
}
思想:
主要运用了ctype.h中的几个重要函数。