#K55407. Character Frequency Counter
Character Frequency Counter
Character Frequency Counter
You are given a string s
via standard input. Your task is to count the frequency of each character in the string and then output each unique character and its count on a separate line. The output should list characters in alphabetical order (i.e. sorted in increasing order by character).
For example, if the input is "apple", the frequency count is as follows:
- 'a' appears 1 time
- 'e' appears 1 time
- 'l' appears 1 time
- 'p' appears 2 times
Thus, the output should be:
a 1 e 1 l 1 p 2
If the input string is empty, no output should be produced.
Note: Ensure that your solution reads from standard input and writes to standard output.
inputFormat
The input consists of a single line containing the string s
. The string may be empty or contain any visible characters.
Input Format:
outputFormat
For each unique character in the input string, print a line with the character followed by a space and its frequency count. The characters must be printed in increasing alphabetical order.
If the input is an empty string, print nothing.
## sampleapple
a 1
e 1
l 1
p 2
</p>