题解 | #计算某字母出现次数#

计算某字母出现次数

http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

#include "stdio.h"
#include "string.h"

#define cmp ('a'-'A')


int main(void)
{
    char str[1024]={0},C='\0';
    int count=0;
    fgets(str,sizeof(str), stdin);
    scanf("%c",&C);
    for(int i=0;i<strlen(str);i++)

        if((str[i]-C)==0)
            count++;
        else
            if((C>='A')&&(C<='Z')&&((str[i]-C)==cmp))
               count++;
            else
               if((C>='a')&&(C<='z')&&((C-str[i])==cmp))
                count++;
    printf("%d",count);
    return 0;
}
全部评论
为什么定义str为1024个空间就能成功 而1000会失败呢
点赞 回复 分享
发布于 2024-04-29 20:06 湖北

相关推荐

Dream_coding:你是不是只投大厂了
点赞 评论 收藏
分享
评论
16
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务