第九周统计字符个数

来源:互联网 发布:淘宝怎么看评价 编辑:程序博客网 时间:2024/06/06 05:26
Description 
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。 
Input 
一行字符 
Output 
统计值 
Sample Input 
aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123 
Sample Output 

23 16 2 4

#include "stdio.h"int main(){    int alpha=0, number=0, space=0, others=0;    char ch;    while ((ch=getchar())!='\n')    {        if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))            alpha++;        else if (ch>='0'&&ch<='9')            number++;        else if (ch==' ')            space++;        else            others++;    }    printf("%d %d %d %d\n", alpha, number, space, others);    return 0;}


0 0
原创粉丝点击