AcWing 3631. 字母频率
原题链接
简单
作者:
GamorH
,
2024-03-15 13:22:01
,
所有人可见
,
阅读 13
数组模拟哈希统计,k 为 字母, v 为出现频率
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
char cnt[26];
int ans = -1;
int index;
int main() {
string str;
getline(cin, str);
string lower;
for (char c : str) {
lower += tolower(c);
}
for (char c : lower) {
if (isalpha(c)) {
cnt[c-'a']++;
}
}
for(int i = 0; i < 25; i++)
if(cnt[i] > ans)
{
ans = cnt[i];
index = i;
}
char res = index + 'a';
cout<< res << " " << ans;
return 0;
}