An antique adding machine displays its running tally as a chain of digit wheels, ordered left to right from most significant to least significant; each wheel shows a value from 0 to 9. The chain never shows a redundant leading zero, except when the tally is exactly zero (a single wheel showing 0). Turning the crank once adds exactly one to the tally: digits carry to the left exactly as in ordinary addition, and if every wheel rolls over from 9 to 0 (for example 999 becoming 1000), a brand-new wheel showing 1 is added to the front of the chain. Given the current chain of wheel digits, output the chain of wheel digits after the crank is turned once.
Print the resulting wheel digits after the crank is turned once, space-separated on a single line, from most significant to least significant, with no leading zero unless the result is exactly the single digit 0.
Example 1
Input
3 1 2 3
Expected
1 2 4
Explanation
The wheels show 123. Adding one gives 124, with no carry beyond the last wheel, so the output is 1 2 4.
Example 2
Input
3 9 9 9
Expected
1 0 0 0
Explanation
The wheels show 999. Adding one rolls every wheel over to 0 and carries out past the leftmost wheel, so a new wheel showing 1 is prepended, giving 1000, i.e. 1 0 0 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →