Random Words

2

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

Given N words \(a_i\) of lowercase letters. Arrange these words such that word \(a_i\) of length \(l_i\) comes before word \(a_j\) of length \(l_j\) if

1) \(l_i < l_j\).
OR
2) \(l_i = l_j\) and the first different letter in \(a_i\) < corresponding letter in \(a_j\). Letters are compared with respect to their ASCII Value.

For example: \(a_i\) = "arm", \(a_j\) = "ant", so "ant" comes before "arm" because second letter in \(a_j\) n < second letter in \(a_i\) r.

Input:

In the first line: Given an integer N.
In the second line: N strings \(a_i\) follow.

Output:

Print the words in the order illustrated in the question.

Constraints:

\(1 \le N \le 100\).
\(1 \le l_i \le 10\).

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

?