#K51397. Unique Character Count
Unique Character Count
Unique Character Count
You are given a string s
containing a sequence of characters. Your task is to count the number of occurrences for each unique character in s
and then output the counts in ascending order of the characters.
You need to implement two functions:
count_unique_characters(s)
: which takes the input string and returns a dictionary (or map) with each unique character as a key and its number of occurrences as the value. The keys should be sorted in ascending order.format_output(counter)
: which takes the dictionary (or map) and produces a formatted string output where each line contains the character and its count separated by a space.
The final solution should read the input from standard input (stdin) and output the result to standard output (stdout).
Note: If any mathematical formulas are required, they should be written in LaTeX format. In this problem, counting occurrences is straightforward and no additional formulas are necessary.
inputFormat
The input consists of a single line containing the string s
whose unique characters are to be counted.
outputFormat
Output the count of each unique character, one per line. Each line should contain the character and its corresponding count separated by a single space. The lines must be in ascending order of the characters.
## sampleab12ab34
1 1
2 1
3 1
4 1
a 2
b 2
</p>