题目
思路
这道题要看清题意,只要求输出小写英文字母,只需要用一个26大小的数组存储对应字符数即可
代码
#include <iostream>
#include <istream>
#include <memory.h>
using namespace std;
int main(){
string test;
getline(cin,test);
int mp[26];
memset(mp,0,sizeof(mp));
char maxChar;
int maxCnt = 0;
//只对英文字母进行处理,其余字符直接跳过
for(char e : test){
if(e>='A' && e<='Z')
mp[e-'A']++;
else if(e>='a' && e<='z')
mp[e-'a']++;
}
for(int i=0; i<26; ++i){
if(mp[i] > maxCnt){
maxCnt = mp[i];
maxChar = 'a'+i;
}
}
cout << maxChar << " " << maxCnt;
return 0;
}