9-统计字符个数

来源:互联网 发布:社交网络 下载 编辑:程序博客网 时间:2024/06/01 19:29

作者:蔡伟

完成日期:2016.10.27

题目描述:输入一行字符,分别统计其中字母数字空格和其他字符的数量

输入样例:absdjk  8283 *&%

输出结果:6  4  3  3

#include <stdio.h>#include <stdlib.h>int main(){    int alpha=0,number=0,space=0,other=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            other++;    }    printf("%d %d %d %d\n",alpha,number,space,other);    return 0;}<img src="http://img.blog.csdn.net/20161027092134960?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


 

0 0
原创粉丝点击