#C3157. Group Words by Length
Group Words by Length
Group Words by Length
Given a list of words, your task is to group them by their length. For each word \(w\) in the input, let \(|w|\) be the length of the word. You must then output each group on a separate line. The words in each group should be sorted in alphabetical order, and the groups must be printed in increasing order of the word lengths.
Example:
Input: apple bat banana ape grape kiwi Output: 3: ape bat 4: kiwi 5: apple grape 6: banana
inputFormat
The input is given via standard input (stdin) as a single line containing space-separated words.
outputFormat
For each distinct word length, output a line in the following format: length: word1 word2 ...
. The words in each line should be sorted alphabetically, and the lines should be ordered by increasing word length.
apple bat banana ape grape kiwi
3: ape bat
4: kiwi
5: apple grape
6: banana
</p>