题解 | #统计字符#

统计字符

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

相关推荐

点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:35
虽然不怎么光彩,经过这件事,可能我真的要去认同“面试八股文早该淘汰!不会用AI作弊的程序员=新时代文盲!”这句话了
HellowordX:Ai的出现是解放劳动力的,不是用来破坏公平竞争环境的,这样下去,轻则取消所有线上面试,严重了会影响整个行业对所有人产生影响,企业会拉高入职考核各种离谱考核会层出不穷
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
8
收藏
分享

创作者周榜

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