Problem
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
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"].
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"].
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Skip spaces, but count every other ASCII character exactly as it appears.
Hinweis 2
Accumulate counts in a frequency table, then output distinct characters once.
Hinweis 3
Sort by character code so uppercase and lowercase order naturally follows ASCII.
Erwartete Komplexität
O(n + m log m) time, O(m) extra space
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.