P1601 A + B Problem (High Precision), p1601problem

Source: Internet
Author: User

P1601 A + B Problem (High Precision), p1601problem
Background

None

Description

High-Precision addition. x is equivalent to a + B problem. [B] [color = red] Negative numbers are not considered. [/color] [/B]

Input/Output Format Input Format:

Enter a and B in two rows <= 10 ^ 500

Output Format:

The output contains only one row, representing the value of A + B.

Input and Output sample Input example #1:
11
Output sample #1:
2
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 const int MAXN=100001; 7 char a1[MAXN],b1[MAXN]; 8 int a[MAXN],b[MAXN]; 9 int ans[MAXN];10 int x;11 int main()12 {13     scanf("%s %s",a1,b1);14     int la=strlen(a1);int lb=strlen(b1);15     for(int i=0;i<la;i++)16         a[i]=a1[la-i-1]-48;17     for(int i=0;i<lb;i++)18         b[i]=b1[lb-i-1]-48;19     int i=0;20     for(i=0;i<max(la,lb);i++)21     {22         ans[i]=(a[i]+b[i]+x)%10;23         x=(a[i]+b[i]+x)/10;24     }25     ans[i]=x;26     int lc=max(la,lb);27     int flag=0;28     for(int i=lc;i>=0;i--)29     {30         if(ans[i]==0&&flag==0&&i>0)31             continue;32         else flag=1;33         printf("%d",ans[i]);34     }35     36     return 0;37 }

 

Related Article

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.