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

计算某字母出现次数

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

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    string str;
	getline(cin, str);
    scanf("%c",&c);
    if(c>='A'&&c<='Z') c+=32;
    int cnt=0;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]>='A'&&str[i]<='Z') str[i]+=32;
        if(str[i]==c) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
全部评论

相关推荐

喜欢核冬天的哈基米很想上市:会爆NullPointerException的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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