Đề bài
Xem bản dịchCount 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.
Ràng buộc
0 ≤ length ≤ 10,000
Ví dụ
Đầu vào:
text = "hello"
Kết quả mong đợi:
expected = ["e:1", "h:1", "l:2", "o:1"]
Đầu vào:
std::string text = "hello";
Kết quả mong đợi:
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
Đầu vào:
string text = "hello";
Kết quả mong đợi:
string[] expected = new string[] {"e:1", "h:1", "l:2", "o:1"};
Giải thích
e:1, h:1, l:2, o:1 sorted by character: ["e:1", "h:1", "l:2", "o:1"].
Đầu vào:
text = "a a A"
Kết quả mong đợi:
expected = ["A:1", "a:2"]
Đầu vào:
std::string text = "a a A";
Kết quả mong đợi:
std::vector<std::string> expected = {"A:1", "a:2"};
Đầu vào:
string text = "a a A";
Kết quả mong đợi:
string[] expected = new string[] {"A:1", "a:2"};
Giải thích
Spaces are skipped; "A" sorts before "a": ["A:1", "a:2"].
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.