#K67347. Group Employees by Starting Character
Group Employees by Starting Character
Group Employees by Starting Character
You are given a list of employee IDs. Your task is to group the employee IDs based on the first character of each ID. If an ID begins with a digit, it should be grouped under the '#' key. Otherwise, group the ID by its starting alphabet character.
For each group, the IDs must be sorted in lexicographical order. After grouping, the groups themselves should be printed in ascending lexicographical order of their keys. In other words, if the '#' group exists, it will always appear first since '#' is lexicographically smaller than letters.
Input Format
- The first line contains an integer \(N\) representing the number of employee IDs.
- The following \(N\) lines each contain a non-empty string representing an employee ID.
Output Format
- For each group, output a line starting with the group key, followed by the sorted employee IDs in that group separated by a single space.
- The groups must be printed in ascending lexicographical order of the keys.
Example
Input: 5 alice123 bob456 charlie789 123dave eve321</p>Output:
123dave
a alice123 b bob456 c charlie789 e eve321
inputFormat
The input is read from standard input (stdin). The first line contains an integer N, the number of employee IDs. Each of the following N lines contains one employee ID (a non-empty string).
outputFormat
Output the grouped employee IDs to standard output (stdout). Each line should contain a group key followed by a space-separated list of employee IDs belonging to that group. The groups should be printed with keys in lexicographical order, and the employee IDs within each group should also be sorted in lexicographical order.## sample
5
alice123
bob456
charlie789
123dave
eve321
# 123dave
a alice123
b bob456
c charlie789
e eve321
</p>