Untitled
unknown
c_cpp
2 years ago
517 B
5
Indexable
#include <iostream>
#include <map>
#include <string>
void count(std::string word, std::map<char, unsigned int> &letters) {
for (auto i : word) {
if (letters.find(i) == letters.end()) {
letters[i] = 1;
}
else {
letters[i] += 1;
}
}
}
int main() {
std::map<char, unsigned int> letters;
std::string word;
std::cin >> word;
count(word, letters);
for (auto i = letters.begin(); i != letters.end(); ++i)
{
std::cout << i->first << " : " << i->second << std::endl;
}
};
Editor is loading...
Leave a Comment