题解 | #统计字符#

统计字符

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

#include<stdio.h>
#include<string.h>
int main() {
    char str[1001] = {'\0'};
    while (gets(str)) {
        int len = strlen(str);
        int charac = 0, blank = 0, num = 0, other = 0;
        for (int i = len - 1; i >= 0; i--) {
            //字母计数(区分大小写)
            if ((('a' <= str[i])&&(str[i] <= 'z')) || (('A' <= str[i])&&(str[i] <= 'Z'))) charac++;
            else if (str[i] == ' ') blank++;  //空格计数
            else if (('0' <= str[i]) && (str[i] <= '9')) num++;  //数字计数
            else other++;  //其他字符计数
        }
        printf("%d\n%d\n%d\n%d\n", charac, blank, num, other);
    }
}
全部评论
gets为什么会出错呀
点赞 回复 分享
发布于 2022-05-05 11:38

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
评论
8
收藏
分享

创作者周榜

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