Tous les défis
Facile 0 résolus 0 % de réussite

Character Frequency

Count how often each character appears.

Count every character in text except spaces. Report each distinct character once as "character:count", sorted by character code (so uppercase letters come before lowercase).

Implement character_frequency(text).

Input

text: The text to count (ASCII characters).

Output

Return the list of "character:count" entries.

Contraintes

0 ≤ length ≤ 10,000

Exemples

Exemple 1
Entrée :
text = "hello"

Sortie attendue :
expected = ["e:1", "h:1", "l:2", "o:1"]
Entrée :
std::string text = "hello";

Sortie attendue :
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
Entrée :
string text = "hello";

Sortie attendue :
string[] expected = new string[] {"e:1", "h:1", "l:2", "o:1"};

Explication

e:1, h:1, l:2, o:1 sorted by character: ["e:1", "h:1", "l:2", "o:1"].

Exemple 2
Entrée :
text = "a a A"

Sortie attendue :
expected = ["A:1", "a:2"]
Entrée :
std::string text = "a a A";

Sortie attendue :
std::vector<std::string> expected = {"A:1", "a:2"};
Entrée :
string text = "a a A";

Sortie attendue :
string[] expected = new string[] {"A:1", "a:2"};

Explication

Spaces are skipped; "A" sorts before "a": ["A:1", "a:2"].

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.