Daming A+b

Source: Internet
Author: User

E-Daming A+bTime limit:MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64u SubmitStatus

Description

Say, after a long one months, Xiaoming has grown a lot, so he changed a name called "Daming".
At this time he is not the only one who will do the addition of the "Xiao Ming", and now he will even arbitrary length of the addition of the positive decimal.

Now, give you two positive decimals A and B, your task is to calculate the value of A+b on behalf of Daming.

Input

This topic contains multiple sets of test data, please process to the end of the file.
Each set of test data contains two positive decimals A and B with a length of not more than 400 in a row.

Output

Please output the output a+b value in one line, please output the simplest form. Please see sample Output for detailed requirements.

Sample Input

Sample Output

43.45554344542.1 thought: This question yesterday noon in thinking, separated a few hours, write almost, that is at that time do not know after 0 how to remove, then and learn the younger brother A in exchange, inspiration spontaneously, is judging from the back, is 0 words, continue, remember not 0 of the position, Then output as required. Main idea: I just put the two decimal point alignment control, the left side of the add, the corresponding add to the right (the number of different bits with 0 supplement, so that the left side of the same number of digits, the same number of digits on the same.) Then the right side of the first add, put into the RESULT1 array, RESULT1 control than the right of the number of long 1,result1[0] storage carry, result2 array of the number of left to add the result of the addition, Result2[0] store carry.
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <    Algorithm>using namespace Std;int Main () {string A, B; int Result1[500],result2[500];int Posa,posb,rgta,lfta,rgtb,lftb,i,k,l,pos,j,flg;while (cin>>a>>b) {pos =0;flg=0;memset (result1,0,sizeof (RESULT1)); Memset (Result2,0,sizeof (RESULT2)); if (A.find (".") ==-1) {posa=a.size (); a=a+ ".";}   Else Posa=a.find ("."); if (B.find (".")      ==-1) {posb=b.size ();  B=b+ ".";      123456789. } else Posb=b.find (".");     /23498.78998 rgta=a.size ()-posa-1;     Rgtb=b.size ()-posb-1;     Lfta=posa;     LFTB=POSB;           if (RGTA&GT;RGTB) {for (i=1;i<=rgta-rgtb;i++) b=b+ "0";       Rgtb=rgta;           } else if (RGTA&LT;RGTB) {for (i=1;i<=rgtb-rgta;i++) a=a+ "0";       RGTA=RGTB;         } if (LFTA&GT;LFTB) {for (i=1;i<=lfta-lftb;i++)//b.insert (0, ' 0 '); b= ' 0 ' +b;         LFTB=LFTA; posb=Posa      } else if (LFTA&LT;LFTB) {for (i=1;i<=lftb-lfta;i++)//a.insert (0, ' 0 ');         A= ' 0 ' +a;         LFTA=LFTB;         POSA=POSB;         } K=rgta;          For (I=a.size () -1;i>posa;i--) {result1[k]= (a[i]-' 0 ') + (b[i]-' 0 ');       k--;         } for (i=rgta;i>=1;i--) {RESULT1[I-1]=RESULT1[I-1]+RESULT1[I]/10;       result1[i]=result1[i]%10;         } K=lfta;         for (i=lfta-1;i>=0;i--) {result2[k]= (a[i]-' 0 ') + (b[i]-' 0 '); k--;         } for (i=lfta;i>=1;i--) {RESULT2[I-1]=RESULT2[I-1]+RESULT2[I]/10;       result2[i]=result2[i]%10;          } if (result1[0]!=0) {result2[lfta]+=result1[0]; if (result2[lfta]>=10) {for (i=lfta;i>=1;i--) {result2[i                       -1]=RESULT2[I-1]+RESULT2[I]/10;                        result2[i]=result2[i]%10; if (Result2[I-1]&LT;10) break;       }}} int l=0;               if (result2[0]==0) {for (i=1;i<=lfta;i++) cout<<result2[i];   for (i=rgta;i>=1;i--) {if (result1[i]==0) continue;   else {flg=1;   Pos=i;   Break   }} if (FLG) cout<< ".";  for (i=1;i<=pos;i++) cout<<result1[i];       cout<<endl;          } else {for (i=0;i<=lfta;i++) cout<<result2[i];   for (i=rgta;i>=1;i--) {if (result1[i]==0) continue;   else {flg=1;   Pos=i;   Break   }} if (FLG) cout<< ".";  for (i=1;i<=pos;i++) cout<<result1[i];       cout<<endl; }}return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Daming A+b

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.