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

计算某字符出现次数

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

#include <stdio.h>

int main() {
    int a = 0;
    int b = 0;
    int i = 0;
    char target;
    char str[1000];
    int len;

    scanf("%[^\n]\n", str); //读入第一行的所有数。
    scanf("%c", &target);
    len = strlen(str);

    for (i = 0; i < len; i++) {
        
        if ((str[i] - target) == 0) {
            a++;
        } else if (('Z' >= str[i]) && (str[i] >= 'A')) {
            if ((target - str[i]) == 32) {
                a++;
            }
        } else if (('z' >= str[i]) && (str[i] >= 'a')) {
            if ((str[i] - target) == 32) {
                a++;
            }
        }

    }
    printf("%d", a);


    return 0;
}

全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
秋招吐槽大会
点赞 评论 收藏
分享
2025-11-19 18:44
已编辑
成都理工大学 Java
程序员花海:我面试过100+校招生,大厂后端面试不看ACM,竞赛经历含金量低于你有几份大厂实习 这个简历整体来看不错 可以海投
如何写一份好简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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