Problem 878
Reorder Data in Log Files
Medium · 20 pts · String, Sorting
Problem
Each log line starts with an identifier word, followed by words that are either all lowercase letters (a letter-log) or all digits (a digit-log). Reorder the logs: all letter-logs come first, sorted by their contents (everything after the identifier), with ties broken by the identifier; then all digit-logs in their original order. Print the logs in the new order, one per line. A stable sort with a two-part key handles it.
Input
The first line contains N. Each of the next N lines contains one log.
Output
Print the reordered logs, one per line.
Constraints
1 <= N <= 100; every log has an identifier and at least one more word
Example input
5 dig1 8 1 5 1 let1 art can dig2 3 6 let2 own kit dig let3 art zero
Example output
let1 art can let3 art zero let2 own kit dig dig1 8 1 5 1 dig2 3 6
Explanation
The letter-logs let1 art can, let2 own kit dig and let3 art zero are sorted by content: art can, art zero, own kit dig. The digit-logs dig1 8 1 5 1 and dig2 3 6 follow in their original order.