#C10722. Log File Sorting
Log File Sorting
Log File Sorting
You are given a list of log entries. Each log entry is a string that starts with an identifier followed by space‐separated content. The content can either consist entirely of words (letter-logs) or entirely of digits (digit-logs).
Your task is to sort the logs according to the following rules:
- All letter-logs come before any digit-log.
- Letter-logs are sorted lexicographically by their content (case-insensitive). In case of ties, sort by their identifiers.
- Digit-logs should remain in their relative order (i.e. stable relative to each other).
In other words, if we define the sorting key for a log as follows:
For letter-logs: $$ key = (0, \text{rest.lower()}, \text{identifier}) $$
For digit-logs: $$ key = (1) $$
then the logs should be sorted by this key.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N log1 log2 ... logN ... (repeated for T test cases)
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N, the number of logs.
- The next N lines each contain a log entry.
outputFormat
For each test case, output the sorted log entries (each on a new line) to standard output (stdout). If there are multiple test cases, separate the output of each test case with an empty line.
## sample3
5
a1 9 2 3 1
g1 Act car
zo4 4 7
ab1 off KEY dog
a8 act zoo
4
i1 heh
j1 hee
z1 zee
z2 ack
3
r1 3 4
q3 7 1
k2 5 8
g1 Act car
a8 act zoo
ab1 off KEY dog
a1 9 2 3 1
zo4 4 7
z2 ack
j1 hee
i1 heh
z1 zee
r1 3 4
q3 7 1
k2 5 8
</p>