题解 | #统计字符#

统计字符

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

#include <stdio.h>
#include<malloc.h>
#include<string.h>


int main() {
    char* str = (char*)malloc(1000 * sizeof(char));
    gets(str);
    int i;
    int yw = 0, kg = 0, sz = 0, other = 0;
    int len = strlen(str);
    for (i = 0; i < len; i++) {
        if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
            yw++;
        else if (str[i] >= '0' && str[i] <= '9')
            sz++;
        else if (str[i] == ' ')
            kg++;
        else
            other++;
    }
    printf("%d\n", yw);
    printf("%d\n", kg);
    printf("%d\n", sz);
    printf("%d\n", other);

}

C语言刷题 文章被收录于专栏

自己从头开始刷的C语言

全部评论

相关推荐

10-14 12:20
门头沟学院 Java
迷茫的大四🐶:摊牌了,我是25届的,你们也不招我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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