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

计算某字符出现次数

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

#include <iostream>
using namespace std;

int main() {
    string input1;
    char input2;
    int count = 0;
    getline(cin, input1);
    cin >> input2;
    input2 = tolower(input2);
    for (auto ch : input1) {
        if (tolower(ch) == input2)
            count++;
    } 
    cout << count << endl;       
}
// 64 位输出请用 printf("%lld")

思路:首先读取输入字符串和目标字符串,然后将目标字符串转化为小写,然后遍历输入字符串,统计目标字符串的出现次数

全部评论

相关推荐

03-28 19:11
铜陵学院 C++
有礼貌的山羊追赶太阳:太典了,连笔试都没有开始就因为HC满了而结束了,而且还卡你不让你再投其他部门的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务