Легко Решено: 0 Процент решений: 0%

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.

Ограничения

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. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.