Digit Solitaire | 프로그래밍의 벗 PivotOJ
PivotOJ

Digit Solitaire

시간 제한: 1000ms메모리 제한: 128MB출처: ICPC Mid-Central Regional 2012BOJ 4564

문제

Despite the glorious fall colors in the midwest, there is a great deal of time to spend while on a train from St. Louis to Chicago. On a recent trip, we passed some time with the following game.

We start with a positive integer S. So long as it has more than one digit, we compute the product of its digits and repeat. For example, if starting with 95, we compute 9 × 5 = 45. Since 45 has more than one digit, we compute 4 × 5 = 20. Continuing with 20, we compute 2 × 0 = 0. Having reached 0, which is a single-digit number, the game is over.

As a second example, if we begin with 396, we get the following computations: 

3 × 9 × 6 = 162 
1 × 6 × 2 = 12 
1 × 2 = 2 

and we stop the game having reached 2.

입력

Each line contains a single integer 1 ≤ S ≤ 100000, designating the starting value. The value S will not have any leading zeros. A value of 0 designates the end of the input.

출력

For each nonzero input value, a single line of output should express the ordered sequence of values that are considered during the game, starting with the original value.

예제

예제 1

입력
95
396
28
4
40
0
출력
95 45 20 0
396 162 12 2
28 16 6
4
40 0
코드를 제출하려면 로그인하세요.