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

计算某字母出现次数

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

原理

不计大小写,实际上就是ASCII码值的对比。

code

mine

#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    char s;
    getline(cin, str);
    cin >> s; 
    int cnt = 0;
    for(int i = 0;i < str.length();i++){
        if(str[i] == s || str[i] == s-32 || str[i] == s+32){
            cnt++;
        }
    }
    cout << cnt << endl;

}

others

# python
a=input().lower()
b=input().lower()
print(a.count(b))
全部评论

相关推荐

03-24 17:57
门头沟学院 Java
yakuso:你这头像哈哈哈
点赞 评论 收藏
分享
最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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