C/C++

Самая частая буква

напишите, пожалуйста, на С++
 #include  
#include
#include
using namespace std;
//It's the greatest fastest algorithm in whole world!
//Perdemonokle(c)
//Используйте на свой страх и ужас
struct arr
{
uint8_t a[128];
};
consteval arr get_table()
{
arr aa;
for (uint8_t i = 0; i < 128; ++i) aa.a[i] = 26;
for (uint8_t i = 'a'; i
Sergey Shapoval
Sergey Shapoval
51 417
Лучший ответ
 #include  
#include
#include
#include
#include

using namespace std;

int main() {
string line;
getline(cin, line);
map letters;
auto compare = [](auto& a, auto& b) {
return a.second < b.second;
};
// Обработка строки за один проход
for (auto ch : line) {
if (ch > 0 && isalpha(ch)) {
++letters[toupper(ch)];
}
}

auto pos = max_element(letters.begin(), letters.end(), compare);
for (const auto& [key, value] : letters) {
if (value == pos->second) {
cout.put(key);
}
}
cout
Женька Селин
Женька Селин
53 052
У меня три цикла. Но вложенных нет. Обработка текста одним циклом.
 #include  
#include

int main()
{
const std::string abc = "Aa";
const int lim = 26;
int rez[lim] {0};
int x,y,z,max,tmp;
std::string str;

getline(std::cin,str);

max = 0;

// обработка текста - 1 цикл
for(x = 0; x < str.length(); x++)
{
tmp = str.at(x) - abc.at(0);
if(tmp >= 0 && tmp < lim)
{
rez[tmp]++;
}
else
{
tmp = str.at(x) - abc.at(1);
if(tmp >= 0 && tmp < lim)
{
rez[tmp]++;
}
}
}

// поиск максимум(а,ов)
for(y = 0; y < lim; y++)
{
if(max < rez[y])
max = rez[y];
}

// вывод
for(z = 0; z < lim; z++)
{
if(rez[z] == max)
std::cout
Богдан Ярошенко Вот только, если не будет буков, то выведется весь алфавит.
Тогда конец программы нужно сделать так:

 // вывод
if(max)
{
for(z = 0; z < lim; z++)
{
if(rez[z] == max)
std::cout
Задание для тебя, какой смысл в том, чтобы его делал кто-то другой?