Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
517 B
0
Indexable
Never
#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;
	}
};
Leave a Comment