#C13851. Group Strings by First Letter
Group Strings by First Letter
Group Strings by First Letter
Given a list of strings, group them by their first letter regardless of case. For each string, consider the lowercase form of its first character as the key. Then, output each group on a separate line where the key is followed by a colon and then the strings (in the order they appear in the input) separated by spaces. The groups must be printed in ascending lexicographical order of their keys.
For example, if the input is:
6 apple banana Avocado berry Apricot Blackberry
The output should be:
a: apple Avocado Apricot b: banana berry Blackberry
inputFormat
Input is read from standard input (stdin). The first line contains an integer n which denotes the number of strings. The following n lines each contain one string.
outputFormat
Output the groups to standard output (stdout). For each distinct first letter (converted to lowercase), print a line in the format:
: ...
The groups should be printed in ascending lexicographical order according to the key.## sample
6
apple
banana
Avocado
berry
Apricot
Blackberry
a: apple Avocado Apricot
b: banana berry Blackberry
</p>