Problems > Order by Last Digit

Order by Last Digit

Difficulty: 1000 3500 ms 128 MB

sorting

Sort the values by their last decimal digit; break ties by the value itself (ascending).

Input: the first line has N; the second line has N integers.

Output: the values in the required order.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ ai ≤ 109

Sample Tests

Input 1
5
12 5 30 7 19
Output 1
30 12 5 7 19
Input 2
2
100 2
Output 2
100 2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.