A dynamic array holds a number of single digits (positive numbers), consisting of a large number. Add this number to 1.
For example:
A = [2,3,1,1,4],
return [2,3,1,1,5]
A = [7,8,9],
return [7,9,0].
Format:
The first line enters a positive integer n, the next line, the input array a[n] (each bit is a positive number and is single digit).
Finally, the new array is output.
Sample input
58 9 9) 9 9
Sample output
9 0 0) 0 0
1#include <iostream>2#include <vector>3 using namespacestd;4 intMain () {5 intN, flag =1, temp, K;6CIN >>N;7vector<int> V (N), a (n+1,0);8 for(inti =0; I < n; i++)9CIN >>V[i];Ten intj =0; One for(inti = n1; I >=0; i--){ ATEMP = flag +V[i]; - if(Temp >=Ten){ -Flag =1; theTemp-=Ten; -}Else{ -Flag =0; - } +A[j++] =temp; - } +A[J] =Flag; A for(intj = N; J >=0; j--){ at if(A[j]! =0){ -K =J; - Break; - } - } - for(intL = k; L >=0; l--) incout << A[l] <<" "; - return 0; to}
Garlic Plus One (large number plus 1)