- cin 不会清楚输入缓存中的任何跳过字符,注意使用 cin.ignore(); getline 会读所有字符直到遇到换行符(跳过结束,并且从缓冲区中删除). getchar 会读到\n.
- tolower可以直接放入getchar得返回值(那个char)
- transform(in.begin(),in.end(),in.begin(),::tolower); 这种可以转换字符串为小写字符.
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<string>
#include <algorithm>
#include <cctype>
using namespace std;
int main() {
string in;
getline(cin,in);
char a = tolower(getchar());
if(!in.size()) return 0;
transform(in.begin(),in.end(),in.begin(),::tolower);
int map[128]={0};
for(int i =0; i< in.size();i++){
map[in[i]]++;
}
cout<<map[a]<<endl;
return 0;
}