#include <iostream>
#include <string>
#include <cctype>
#include <map>
// utility function for converting a string to lower case.
std::string as_lower(const std::string& text)
{
std::string result;
for (auto letter : text)
result += static_cast<char>(std::tolower(letter));
return result;
}
int main()
{
// a map is an associative container. In this case a word whose type is
// std::string is associated with a count whose type is unsigned
// http://w...content-available-to-author-only...s.com/reference/map/map/
std::map<std::string, unsigned> words;
// using the words["word"] notation will cause an entry to be created for
// "word" if one doesn't already exist, with a count of 0. Whether it did
// or didn't exist prior to that call, a reference to the count will be
// returned.
// http://w...content-available-to-author-only...s.com/reference/map/map/operator%5B%5D/
std::string word;
while (std::cin >> word) // while a word is succesfully extracted,
words[as_lower(word)]++; // increase the count associated with it.
// print the words and associated counts:
for (auto& w : words)
std::cout << '"' << w.first << "\": " << w.second << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8bWFwPgoKLy8gdXRpbGl0eSBmdW5jdGlvbiBmb3IgY29udmVydGluZyBhIHN0cmluZyB0byBsb3dlciBjYXNlLgpzdGQ6OnN0cmluZyBhc19sb3dlcihjb25zdCBzdGQ6OnN0cmluZyYgdGV4dCkKewogICAgc3RkOjpzdHJpbmcgcmVzdWx0OwoKICAgIGZvciAoYXV0byBsZXR0ZXIgOiB0ZXh0KQogICAgICAgIHJlc3VsdCArPSBzdGF0aWNfY2FzdDxjaGFyPihzdGQ6OnRvbG93ZXIobGV0dGVyKSk7CgogICAgcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4oKQp7CiAgICAvLyBhIG1hcCBpcyBhbiBhc3NvY2lhdGl2ZSBjb250YWluZXIuICBJbiB0aGlzIGNhc2UgYSB3b3JkIHdob3NlIHR5cGUgaXMgCiAgICAvLyBzdGQ6OnN0cmluZyBpcyBhc3NvY2lhdGVkIHdpdGggYSBjb3VudCB3aG9zZSB0eXBlIGlzIHVuc2lnbmVkCiAgICAvLyBodHRwOi8vdy4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