Enter n First, representing a number of numbers, and then entering n groups of data
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include < algorithm> #include <malloc.h>using namespaceStd;CharResU[10000];voidReverse(CharA[10000]){intLeng =Strlen(A);CharTemp; for (intI =0;I<Leng /2;I++) {Temp =A[Leng -I -1];A[Leng -I -1] =A[I];A[I] =Temp; }return ;}Char *Toadd(CharA[10000],CharB[10000]){Reverse(A);Reverse(B);CharMin[10000],Max[10000];if (Strlen(A) >=Strlen(B)) {strcpy_s(Min,B);strcpy_s(Max,A); }Else {strcpy_s(Min,A);strcpy_s(Max,B); }intJinwei =0; for (intI =0;I< (int)Strlen(Min);I++) {if (Min[I] +Max[I] -' 0 ' -' 0 ' +Jinwei>=Ten) {ResU[I] =Min[I] +Max[I] -' 0 ' +Jinwei -Ten;Jinwei =1; }Else {ResU[I] =Min[I] +Max[I] -' 0 ' +Jinwei;Jinwei =0; } }intI; for (I =Strlen(Min);I< (int)Strlen(Max);I++) {if (Max[I]-' 0 ' +Jinwei>=Ten) {ResU[I] =Max[I]+Jinwei -Ten;Jinwei =1; }Else {ResU[I] =Max[I]+Jinwei;Jinwei =0; } }if (Jinwei) {ResU[I] =Jinwei +' 0 ';ResU[++I] =' + '; }ElseResU[I] =' + ';Reverse(ResU);returnResU;}intMain( ){intN;CharA[ -][10000],B[ -][10000];Cin>>N; for (intI =0;I<N;I++) {Cin>>A[I] >>B[I]; } for (intI =0;I<N;I++) {cout<<"Case"<<I+1<< ":"<<Endl;cout<<A[I] << " + "<<B[I] << " = ";Toadd(A[I],B[I]);intK =0; while (ResU[K] ==' 0 ')K++;if (K ==Strlen(ResU)) {cout<<"0";cout<<Endl; }Else { for (intO =K;O<Strlen(ResU);O++)cout<<ResU[O];cout<<Endl; }if (I< (N -1))cout<<Endl; }return0;}
Hangzhou Electric OJ1002 Big Data add