## ECOO '15 R3 P1 - Just the Factoradics, Ma'am

View as PDF

Points:7 (partial)
Time limit:2.0s
Memory limit:64M

Problem type

The factoradic number system is a number system that uses factorials as the place value for each digit. In case you don't know, the factorial value of an integer is written and it evaluates to what you get when you multiply together all the integers from to , like this:

In the factoradic number system, the rightmost "digit" has a base value of , the second digit has a base value of , the third digit has a base value of and the digit has a base value of Each digit of a factoradic number must be less than or equal to , where is the place value of the digit.

For example the factoradic number has digits. See the table at right for a breakdown of place values and highest digit values. To convert a number from the factoradic number system to base , you multiply each digit by its base value and sum them all up.

Because larger factoradic numbers have digits larger than , we separate each digit with a space, as shown in the example below:

The input will contain test cases. Each test case consists of a single line containing a set of non-zero decimal digits concatenated together. The maximum number of digits is . Each line represents a single factoradic number which is missing all its s and all the spaces that are supposed to separate the factoradic digits. Find the smallest legal factoradic number that can be made using the decimal digits in their current order. You may add as many zeroes as you wish and place them anywhere you wish.

#### Sample Input

72
11
12111722
11111722
1566111414121811722

#### Sample Output

7 0 0 0 0 2 0 0
1 1 0
1 2 1 1 1 7 0 0 0 2 2 0 0
11 1 1 1 7 0 0 0 2 2 0 0
15 6 6 11 14 1 4 12 1 8 1 1 7 0 0 0 2 2 0 0

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org