题解 | #计算某字符出现次数#,求指教有没有可以改进的地方

计算某字符出现次数

https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&tqId=21225&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

#include <stdio.h>

int main() {
    char str[1000];
    char cha1,cha2;
    int a=0, b;
    while (scanf("%c", &cha1) != EOF) 
    { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        str[a]=cha1;
        a++;
    }
    cha2=str[a-2];
    for(b=0;a>=4;a--)
    {
        cha1=str[a-4];
       b=b+(tolower(cha1)==tolower(cha2));
    }
    printf("%d",b);
    return 0;
}

全部评论
没有弄明白为什么第二行的字符是索引-2,也就是cha2=str[a-2];。向大佬们请教一下。
点赞
送花
回复
分享
发布于 03-13 22:30 美国

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务