Problem 313
Plus One
Problem
A large non-negative integer is stored as an array of its decimal digits, with the most significant digit first and no leading zeros (unless the number is 0 itself). Add one to the number and print the digits of the result in the same format. Watch out for carries: adding one to 999 gives 1000, which has one more digit than the input.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1]. Each value is a digit from 0 to 9.
Output
Print the digits of the number plus one, separated by spaces.
Constraints
1 <= N <= 100; 0 <= A[i] <= 9; no leading zeros unless the number is 0
Example input
3 1 2 3
Example output
1 2 4
Explanation
The digits 1 2 3 represent 123. Adding one gives 124, so the output is 1 2 4.