题解 | #计算某字母出现次数#C++解法,就单纯统计字符个数来说,还有比map更简单的吗?
计算某字母出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include<bits/stdc++.h> using namespace std; int main() { string str;char ch; getline(cin,str);cin>>ch; map<char,int> m; for(auto x:str) { m[tolower(x)]++; } cout<<m[tolower(ch)]; }