题解 | #计算某字母出现次数#
计算某字母出现次数
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))