1 //2 //Created by Alim on 2017/12/23.3 //4 5 6#include <stdlib.h>7#include <cstring>8#include <iostream>9 using namespacestd;Ten One #defineM 100 A - Charsa[ +]; - Charsb[ +]; the -typedefstruct_node{ - intS[M];//Digital - intL//Digital Length +}node,*Pnode; - + A voidDzs_add (pnode pa,pnode pb,pnode result) { at intI, CC; - Pnode temp; - - if(Pa->l < pb->l) { -temp =PB; -PB =PA; inPA =temp; - } to + for(intj =0; J < pa->l; ++j) { -RESULT->S[J] = pa->S[j]; the } *Result->l = pa->l; $ Panax NotoginsengCC =0; - for(i =0; I < pb->l; ++i) { theResult->s[i] = (Pa->s[i] + pb->s[i] + cc)%Ten; +CC = (Pa->s[i] + pb->s[i])/Ten; A } the if(CC! =0) { +Result->s[i] = result->s[i]+cc; - } $ if(I >= result->l) { $Result->l = i+1; - } - the return; - }Wuyi the voidDzs_jian (pnode pa,pnode pb,pnode result) { - intI, CC; Wu Pnode temp; - About if(Pa->l < pb->l) { $temp =PB; -PB =PA; -PA =temp; - } A for(intj =0; J < pa->l; ++j) { +RESULT->S[J] = pa->S[j]; the } -Result->l = pa->l; $CC =0; the for(i =0; I < pb->l; ++i) { the if(Pa->s[i] >= pb->S[i]) { theResult->s[i] = pa->s[i]-pb->S[i]; the}Else { -Result->s[i +1] -=1; inResult->s[i] = Pa->s[i] +Ten-Pb->S[i]; the } the } About if(I >= result->l) { theResult->l = i+1; the } the } + intMain () { - Node ans,a,b; thecout <<"Please enter a large integer a:"<<Endl;BayiCIN >>sa; thecout <<"Please enter a large integer b:"<<Endl; theCIN >>sb; -A.L = strlen (SA);//processing with a string, calculating the length -B.L =strlen (SB); the the //Backward Storage the intz=0, I; the for(inti = a.l-1; I >=0; i--) { -a.s[z++] = sa[i]-'0'; the } the thez=0;94 for(inti = b.l-1; I >=0; i--) { theb.s[z++] = sb[i]-'0'; the } the //Dzs_add (&a, &b, &ans);98Dzs_jian (&a, &b, &ans); Aboutcout <<"The end result is: \ n"; - for(i = ans.l-1; I >=0; i--) {101cout<<Ans.s[i];102 }103 104cout <<Endl; the return 0;106}
Algorithm notes-----Large integers-+------Array---efficiency