#K95572. Most Common Characters
Most Common Characters
Most Common Characters
You are given a string S
consisting of lowercase English letters. Your task is to count the frequency of each character in the string and print the top three characters along with their counts.
The characters must be sorted primarily by their frequency in descending order. In the case of a tie (i.e. two or more characters have the same frequency), they should be ordered in lexicographical (alphabetical) order. If the string contains less than three unique characters, print all of them.
The final output should consist of three lines (or fewer if there are less than three unique characters). Each line should contain a character and its respective count separated by a space.
Note: If there are more than three unique characters, only the three with the highest priority as described are printed.
For example, if S = "aabbbccde"
, the output should be:
b 3 a 2 c 2
inputFormat
The input consists of a single line which contains a string S
composed of lowercase English letters.
You should read the input from standard input (stdin).
outputFormat
The output should be printed to standard output (stdout) and consist of at most three lines. Each line must contain a character and its frequency (number of occurrences) separated by a space.
## sampleaabbbccde
b 3
a 2
c 2
</p>