#C13117. Group Strings by Length
Group Strings by Length
Group Strings by Length
Given a list of non-empty strings, your task is to group them by their lengths. For each distinct length, you must output the length followed by the strings that have that length in the order they appear in the input. The groups should be displayed in ascending order of length.
For example, if the input is:
6
apple
bat
cat
banana
dog
elephant
The expected output will be:
3: bat cat dog
5: apple
6: banana
8: elephant
Make sure your solution reads from standard input (stdin) and prints the result to standard output (stdout). If there are no strings, output nothing.
inputFormat
The first line contains an integer N representing the number of strings. The next N lines each contain one non-empty string.
outputFormat
For each distinct string length, output a line in the format:
L: s1 s2 ... sk
where L is the length, and s1, s2, ..., sk are the strings of that length in the order they appeared in the input. The lines must be printed in ascending order of L.## sample
6
apple
bat
cat
banana
dog
elephant
3: bat cat dog
5: apple
6: banana
8: elephant
</p>