Problem H
Nearly Case Insensitive Sort
Languages
en
is
In the middle of the contest your team’s laptop started behaving somewhat strangely. Your teammates Abba and Geir somehow came to the conclusion that some other contestant must be trying to hack into your computer! They immediately get on trying to stop this intrusion and start hammering away at the keyboard full force, both at the same time even.
You do not really know if this checks out, but in any case this is wasting time. To stop further absurdity you grab the laptop charging cable and yank it out. Your teammates look at you with a strange expression on their face, this is a laptop so pulling the charging cable out won’t do much of anything for a few hours yet.
Since that did not work you need to convince them this isn’t sabotage. The best way to do that would be to go through the error logs of the operating system and figure out what’s wrong. The problem is that all these logs are in chronological order and not alphabetical order. This makes it harder to find all the errors relating to one particular thing and figure out how often it is happening. The built-in sorting function only sorts by ASCII value though, so the messages mouse froze and Mouse error won’t end up anywhere near each other.
To rectify this you need to quickly implement a helper script that sorts the lines of the file in alphabetical order, but ignores the difference between upper and lower case. However, in the case that the messages are exactly the same aside from casing, they should be sorted internally by the usual ASCII ordering. The ASCII order is the same as alphabetical, except all upper case letters come before all lower case letters. A space is considered to come before all letters. If one line is the prefix of another, for example key and keyboard then the shorter line comes first.
Input
The first line of input contains a single integer $L$, the number of lines to follow. It will always hold that $1 \leq L \leq 1\, 000$. Next there are $L$ lines, each with at most $64$ characters, the newline character counted among them. Each line only contains upper and lower case English letters, spaces and a newline character at the end. The lines will always contain at least one letter.
Output
Print $L$ lines, the same lines as in the input, except sorted in the right order as described above. Make sure to print no extra whitespace.
Scoring
|
Group |
Points |
Constraints |
|
1 |
15 |
Only lower case letters. |
|
2 |
10 |
Only letters. |
|
3 |
25 |
Only lower case letters and spaces. |
|
4 |
30 |
$L \leq 2$. |
|
5 |
20 |
No further constraints. |
| Sample Input 1 | Sample Output 1 |
|---|---|
4 mouse error crash froze |
crash error froze mouse |
| Sample Input 2 | Sample Output 2 |
|---|---|
5 Mouse mous mOUs mouSe mous |
mOUs mous mous Mouse mouSe |
| Sample Input 3 | Sample Output 3 |
|---|---|
5 mouse mouse mouse wheel mouse wheel mouse |
mouse mouse mouse mouse wheel mouse wheel |
