Random Words

2

6 votes
Sorting, Implementation, Recruit, approved, Easy, Approved
Problem

Given N words ai of lowercase letters. Arrange these words such that word ai of length li comes before word aj of length lj if

1) li<lj.
OR
2) li=lj and the first different letter in ai < corresponding letter in aj. Letters are compared with respect to their ASCII Value.

For example: ai = "arm", aj = "ant", so "ant" comes before "arm" because second letter in aj n < second letter in ai r.

Input:

In the first line: Given an integer N.
In the second line: N strings ai follow.

Output:

Print the words in the order illustrated in the question.

Constraints:

1N100.
1li10.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?