Question B: "High precision" simple high-precision addition

Source: Internet
Author: User

Question B: "High precision" simple high-precision addition time limit: 1 Sec memory limit: up to MB
Submitted by: 94 resolution: 27
Submitted State [Discussion Version] Topic description Asura King solved the computer's memory limit problem, finally can use the computer for a large magic operation, he handed the Wolf's first task is to calculate two nonnegative integers a, b and, where A and b in the number of digits within 5,000 bits. Input a total of two rows of data, the first behavior of a nonnegative integer A, the second behavior a nonnegative integer b,a, B, the number of bits are within 5000. Output output a non-negative number, that is, the sum of two. Sample input
11111111112222222222
Sample output
3333333333
Tips
#include <iostream> #include <cstring>using namespace Std;int main () {   int c,i,j,cnt;    int res[1111];    Char a[1111],b[1111];   Gets (a);   Gets (b);        int Lena=strlen (a);        int Lenb=strlen (b);        c=0;        cnt=0;        For (i=lena-1,j=lenb-1;i>=0&&j>=0;i--, j--)        {            int p= (a[i]-' 0 ') + (b[j]-' 0 ') +c;            res[cnt++]=p%10;            C=P/10;        }       while (i>=0)        {            int p= (a[i]-' 0 ') +c;            res[cnt++]=p%10;            C=P/10;            i--;        }        while (j>=0)        {            int p= (b[j]-' 0 ') +c;            res[cnt++]=p%10;            C=P/10;           j--;        }        if (c)        {            res[cnt++]=c;        }        for (i=cnt-1;i>=0;i--)        {            cout<<res[i];        }        Puts ("");    return 0;}

  

Question B: "High precision" simple high-precision addition

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.