Sorting by the last digit
Kotlin
Easy
sorting
Task «Sorting by the last digit»
Write a program that reads an array of integers and sorts it in ascending order by the last digit of the numbers. If the last digits match, the original order is preserved (stable sort). Output the sorted array.
Input Format
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of elements. The second line contains N integers separated by spaces.
Output Format
Output N numbers separated by spaces — the sorted array.
Examples
Example 1
INPUT
4
11 21 31 12
OUTPUT
11 21 31 12
Example 2
INPUT
3
100 1
200 2
150 3
150
OUTPUT
100 200 1
main.kt