Garlic Plus One (large number plus 1)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.