分类统计字符个数(15 分)

统计字符个数
Description
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
Input
一行字符
Output
统计值
Sample Input
aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123
Sample Output
23 16 2 4

#include<stdio.h>
int main()
{
    int char_num=0,int_num=0,space_num=0,other_num=0;
    char ch;
    while((ch=getchar())!='\n')
    {
        if(ch<='z'&&ch>='a'||ch<='Z'&&ch>='A')
        {
            char_num++;
        }
        else if(ch<='9'&&ch>='0')
        {
            int_num++;
        }
        else if(ch==' ')
        {
            space_num++;
        }
        else
        {
            other_num++;
        }
    }
    printf("字母个数:%d\n",char_num);
    printf("数字个数:%d\n",int_num);
    printf("空格个数:%d\n",space_num);
    printf("其他个数:%d\n",other_num);
}

猜你喜欢

转载自www.cnblogs.com/2228212230qq/p/9260456.html