HJ2 计算某字符出现次数
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main() {
string tmpStr;
char tmpChar;
unordered_map<char, int>myMap;
getline(cin, tmpStr);
cin>>tmpChar;
for(int i=0 ; i<tmpStr.size() ;i++)
myMap[tmpStr[i]]++;
if(tmpChar >= '0' && tmpChar <= '9')
{
cout<<myMap[tmpChar];
return 0;
}
if(tmpChar >= 'a' && tmpChar <= 'z') tmpChar = tmpChar - 'a';
else if(tmpChar >= 'A' && tmpChar <= 'Z') tmpChar = tmpChar - 'A';
cout<< myMap[tmpChar + 'a'] + myMap[tmpChar + 'A'];
return 0;
}