Einfach 0 gelöst 0% Erfolgsquote

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.

Einschränkungen

0 ≤ length ≤ 10,000

Beispiele

Beispiel 1
Eingabe:
text = "hello"

Erwartete Ausgabe:
expected = ["e:1", "h:1", "l:2", "o:1"]
Eingabe:
std::string text = "hello";

Erwartete Ausgabe:
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
Eingabe:
string text = "hello";

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

Erläuterung

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

Beispiel 2
Eingabe:
text = "a a A"

Erwartete Ausgabe:
expected = ["A:1", "a:2"]
Eingabe:
std::string text = "a a A";

Erwartete Ausgabe:
std::vector<std::string> expected = {"A:1", "a:2"};
Eingabe:
string text = "a a A";

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

Erläuterung

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.