Sorting by the last digit
Python
Easy
sorting
Task «Sorting by the last digit»
Write a program that sorts a list of integers in ascending order by the last digit. If the last digits are the same, the numbers should be sorted in descending order. The first line of input contains the number n (1 ≤ n ≤ 1000). The second line contains n integers separated by spaces, each from -1000 to 1000. Output the sorted list of numbers separated by spaces.
Input Format
First line: an integer n. Second line: n integers separated by spaces.
Output Format
One line with n numbers sorted according to the rule, separated by spaces.
Examples
Example 1
INPUT
5
12 23 34 45 56
OUTPUT
12 23 34 45 56
Example 2
INPUT
4
-1 11 -21 31
OUTPUT
31 11 -1 -21
Example 3
INPUT
4 2
6 10 3 5
OUTPUT
10 2 3 6
Example 4
INPUT
3
100 200 300
OUTPUT
300 200 100
Example 5
INPUT
3 3
7 11 13
OUTPUT
11 3 7
main.py