题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

#include <stdio.h>

int main() {
    char c;
    int enCount=0;
    int spCount=0;
    int nuCount=0;
    int otCount=0;
    while(scanf("%c",&c)&&c!='\n'){
        if(c>='a'&&c<='z'||c>='A'&&c<='Z'){
            enCount++;
        }
        else if(c>='0'&&c<='9'){
            nuCount++;
        }
        else if(c==' '){
            spCount++;
        }
        else{
            otCount++;
        }
    }
    printf("%d\n%d\n%d\n%d\n",enCount,spCount,nuCount,otCount);
    return 0;
}

逐个获取字符,分别根据ASCII统计,最后输出即可。

全部评论

相关推荐

写不来代码的小黑:这么小的城市能有做it的公司也不容易
点赞 评论 收藏
分享
07-15 12:24
重庆大学 运营
坏消息:和好工作擦肩而过
给点吧求求了:怎么可能因为差几秒,估计就是简历更好看婉拒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务