โจทย์
ดูฉบับแปล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.
เงื่อนไข
0 ≤ length ≤ 10,000
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
text = "hello"
ผลลัพธ์ที่คาดหวัง:
expected = ["e:1", "h:1", "l:2", "o:1"]
อินพุต:
std::string text = "hello";
ผลลัพธ์ที่คาดหวัง:
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
อินพุต:
string text = "hello";
ผลลัพธ์ที่คาดหวัง:
string[] expected = new string[] {"e:1", "h:1", "l:2", "o:1"};
คำอธิบาย
e:1, h:1, l:2, o:1 sorted by character: ["e:1", "h:1", "l:2", "o:1"].
ตัวอย่างที่ 2
อินพุต:
text = "a a A"
ผลลัพธ์ที่คาดหวัง:
expected = ["A:1", "a:2"]
อินพุต:
std::string text = "a a A";
ผลลัพธ์ที่คาดหวัง:
std::vector<std::string> expected = {"A:1", "a:2"};
อินพุต:
string text = "a a A";
ผลลัพธ์ที่คาดหวัง:
string[] expected = new string[] {"A:1", "a:2"};
คำอธิบาย
Spaces are skipped; "A" sorts before "a": ["A:1", "a:2"].
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน