#K39902. Word Categorization by First Letter
Word Categorization by First Letter
Word Categorization by First Letter
Given a line of space-separated words, your task is to categorize the words based on their first letter and count how many words start with each letter. The output should list the letter and the corresponding count in ascending order based on the letter.
Example:
Input: apple banana apricot orange olive
Output:
a 2
b 1
o 2
If the input is empty, no output should be produced.
inputFormat
The input is provided via standard input (stdin) and consists of a single line containing space-separated words. There is no extra input.
outputFormat
The output should be written to standard output (stdout). For each unique first letter (sorted in ascending order), print a line containing the letter and the count of words starting with that letter, separated by a space. If the input is empty, do not print anything.
## sampleapple banana apricot orange olive
a 2
b 1
o 2
</p>