题解 | #计算某字母出现次数#
计算某字母出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
为何不用哈希表:
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
char ch;
unordered_map<int, int> hashtable;
while ((ch = cin.get()) != '\n') {
++hashtable[ch];
}
cin.get(ch);
if (ch <='Z')
cout<<hashtable[ch]+hashtable[ch+32];
else
cout<<hashtable[ch]+hashtable[ch-32];
return 0;
}