#C11433. Unique Character Frequency Counter
Unique Character Frequency Counter
Unique Character Frequency Counter
Given a string, your task is to count the frequency of each unique character present in the input string and then output the result. The output should list each character followed by its frequency in a specific format, where each line contains a character and its count in the format character: frequency. The characters in the output must be sorted in ascending lexicographical order.
For example, if the input is hello
, the program should output:
e: 1 h: 1 l: 2 o: 1
Implement your solution such that it reads the input from stdin
and writes the output to stdout
. Ensure that your program can handle different kinds of input strings including strings with repeated characters.
Note: The frequency count should be computed for each character exactly as it appears.
inputFormat
The input consists of a single line containing a string S. The string may contain letters, digits, or other symbols.
Input is provided via stdin
.
outputFormat
Output the frequency of each unique character in the string. For each character, print a line in the format:
Characters must be output in ascending lexicographical order. The output should be sent to stdout
.
hello
e: 1
h: 1
l: 2
o: 1
</p>