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

计算某字符出现次数

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

#include <iostream>
#include <string>
#include <cctype> 
#include <algorithm>
using namespace std;
int ch_of_cnt(const string& str,const char& ch)
{
    int cnt = 0;
    for (char c : str) {    
        if (isalpha(c) && tolower(c) ==tolower(ch)) {
                cnt++;
        } else if (c == ch) {
                cnt++;
        }
    }
    return cnt;
}

int main() {
    string str1,str2 ;
    getline(cin,str1); 
    getline(cin,str2);
    char ch = str2.front();
    cout << ch_of_cnt(str1,ch) <<endl;
}

// 64 位输出请用 printf("%lld")

全部评论

相关推荐

好消息是活的像个人了,周末可以约会吃饭打游戏了坏消息是钱没了,当初来小红书就是为了钱啊哭笑不得😭
犯困嫌疑人:好事儿啊,取消大小周能有更多自己的时间,周末还能约对象玩,这不美滋滋?
投递小红书等公司6个岗位 > 小红书取消大小周
点赞 评论 收藏
分享
03-07 13:32
门头沟学院 C++
未来可欺a:读研吧,这简历只适合学历高的,本科大概率只能干开发,你这个简历开发不匹配,算法和深度学习的话学历又不够
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务