, , . , , , undefined. , , 0x00-0x7F, , UTF-8, :
char frequncies [256] = {};
frequencies ['á'] = 9;
, , :
template <typename charT>
charT most_frequent (const basic_string <charT>& str)
{
constexpr auto charT_max = numeric_limits <charT>::max ();
constexpr auto charT_min = numeric_limits <charT>::lowest ();
size_t frequencies [charT_max - charT_min + 1] = {};
for (auto c : str)
++frequencies [c - charT_min];
charT most_frequent;
size_t count = 0;
for (charT c = charT_min; c < charT_max; ++c)
if (frequencies [c - charT_min] > count)
{
most_frequent = c;
count = frequencies [c - charT_min];
}
if (frequencies [charT_max - charT_min] > count)
return charT_max;
return most_frequent;
}
, ( construct_array), std::array <size_t, numeric_limits <charT>::max () - numeric_limits <charT>::lowest () + 1>. max for , . std::map <std::string, std::array <...>> . :
char most_frequent (string s)
{
static map <string, array <...>> cache;
if (cache.count (s) == 0)
map [s] = construct_array (s);
}
. , . , - , , - , ; , , , .