#include<iostream>
#include<string>
#include<cctype>
std::string to_lower(std::string s)
{
std::string result;
for (auto ch : s)
result += std::tolower(ch);
return result;
}
std::string clean(std::string s)
{
std::string result;
for (auto ch : s)
if (isalpha(ch))
result += ch;
return result;
}
std::string process(std::string s)
{
return to_lower(clean(s));
}
unsigned as_index(char ch)
{
return ch - 'a';
}
std::string get_line(std::string prompt)
{
std::string line;
std::cout << prompt;
std::getline(std::cin, line);
return line;
}
int main()
{
const unsigned counts_size = 26;
int counts[counts_size] = {}; // initialize all elements to 0.
std::string raw_text = get_line("Enter a string:\n> ");
std::string text = process(raw_text);
for (unsigned i = 0; i < text.length(); ++i)
++counts[ as_index(text[i]) ];
for (unsigned i = 0; i < text.length(); ++i)
std::cout << text[i] << ": " << counts[ as_index(text[i]) ] << '\n';
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8Y2N0eXBlPgoKc3RkOjpzdHJpbmcgdG9fbG93ZXIoc3RkOjpzdHJpbmcgcykKewogICAgc3RkOjpzdHJpbmcgcmVzdWx0OwogICAgZm9yIChhdXRvIGNoIDogcykKICAgICAgICByZXN1bHQgKz0gc3RkOjp0b2xvd2VyKGNoKTsKICAgIHJldHVybiByZXN1bHQ7Cn0KCnN0ZDo6c3RyaW5nIGNsZWFuKHN0ZDo6c3RyaW5nIHMpCnsKICAgIHN0ZDo6c3RyaW5nIHJlc3VsdDsKICAgIGZvciAoYXV0byBjaCA6IHMpCiAgICAgICAgaWYgKGlzYWxwaGEoY2gpKQogICAgICAgICAgICByZXN1bHQgKz0gY2g7CgogICAgcmV0dXJuIHJlc3VsdDsKfQoKc3RkOjpzdHJpbmcgcHJvY2VzcyhzdGQ6OnN0cmluZyBzKQp7CiAgICByZXR1cm4gdG9fbG93ZXIoY2xlYW4ocykpOwp9Cgp1bnNpZ25lZCBhc19pbmRleChjaGFyIGNoKQp7CiAgICByZXR1cm4gY2ggLSAnYSc7Cn0KCnN0ZDo6c3R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