注意:\color{red}注意:注意:
1.全部转换为小写字母
2.只需要统计英文字母的字符
3.注意出现次数相同时,需要输出ASCII码小的那个
#include <iostream>
#include <string>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(){
string str;
getline(cin, str);
transform(str.begin(), str.end(),str.begin(),::tolower);
unordered_map<char, int> mp;
int Max = 0;
char ch;
for(auto c: str) {
if(isalpha(c)){
mp[c]++;
if(mp[c] > Max){
Max = mp[c];
ch = c;
}else if(mp[c] == Max && c < ch) ch = c;
}
}
cout<<ch<<" "<<Max<<endl;
return 0;
}

本文介绍了一个使用C++实现的程序,该程序能够读取一行输入的字符串,将其转换为小写,并统计其中出现频率最高的英文字母。在出现多个字母频率相同的情况下,程序会输出ASCII码最小的那个字母及其出现次数。

3万+

被折叠的 条评论
为什么被折叠?



