SAC '22 Code Challenge 3 P3 - Bob Sort

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Java 1.5s
Python 2.0s
Memory limit: 256M

Author:
Problem type

To celebrate the upcoming CCC (Canadian Computing Contest), Max decided to define a new sorting algorithm called Bob Sort.

Bob Sort involves log10(max(Ai))+1 rounds of sorting.

For the rth round, Bob Sort looks at the r rightmost digits, di:

If there are fewer than r digits in element i, the left-aligned missing digits are set to 0.

Then, Bob Sort sorts the elements by their corresponding value (di) in non-decreasing order.

Can you Bob Sort the array into increasing order?

Constraints

1N100000

1Ai109

All Ai are distinct.

Input Specification

The first line will contain N, the number of elements in the array.

The next line will contain N space-separated integers, the elements of the array.

Output Specification

Output log10(max(Ai))+1 lines, the array after each round of sorting.

Note: Within a round, ties do not need to be broken between elements with the same value, di.

Sample Input 1

Copy
6
2 105 12 1 15 65

Sample Output 1

Copy
1 2 12 105 15 65
1 2 105 12 15 65
1 2 12 15 65 105

Sample Input 2

Copy
1
100

Sample Output 2

Copy
100
100
100

Comments


  • -1
    Casio991ms  commented on Jan. 22, 2023, 5:51 p.m.

    Stupid problem. Gives wrong answer for printing extra space after line.