280. Sort Words by Length
Sort n words by length, shortest first. Words of equal length keep the
order they had in the input.
apple be cat do -> be do cat apple
Two things are being practised here. Sorting by a computed property rather than
by the values themselves, and stability again: be and do are both two
letters, and be came first.
This is the shape of almost every real sort you will write, because real data is records sorted by one of their fields rather than bare numbers.
Constraints - `1 ≤ n ≤ 100000` - `1 ≤ word length ≤ 20` - Words contain lowercase letters only.
Input
The first line contains an integer n.
Each of the next n lines contains one word of lowercase letters.
Output
Print the words ordered by length, ties keeping input order, separated by single spaces.