#C10283. Group Strings by Their First Character
Group Strings by Their First Character
Group Strings by Their First Character
You are given a list of strings. Your task is to group these strings by their first character. If a string is empty, consider its first character as an empty string.
The output should be a JSON dictionary where each key is the first character and the corresponding value is a list of strings starting with that character. For consistency, output the keys in lexicographical order.
Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line contains an integer n which represents the number of strings.
The following n lines each contain a string. These strings can be non-empty or empty.
outputFormat
Output a JSON object (dictionary) where each key is the first character of the strings (or an empty string for empty inputs) and the value is a list of all strings that start with that character. The keys should be output in lexicographical order.
## sample5
apple
apricot
banana
blueberry
cherry
{"a":["apple","apricot"],"b":["banana","blueberry"],"c":["cherry"]}