The first behavior of the input file is an integer n, which indicates that the input file is followed by n sets of data, no group of data contains a maximum of 100 rows, each line has a very long decimal integer, the length of the integer is no more than 100 characters, and contains only numbers, the last behavior of each group of data 0, indicating the end of the set
For each set of data on the input file, output their and.
This problem is different from the two large numbers added, is the addition of multiple large numbers, when summed, has its unique: vertical addition
#include <iostream>#include<stdio.h>#include<string.h>Const intm= $;using namespacestd;intMain () {CharBuffer[m]; intArray[m][m],answer[m]; intn,maxn,len,num_integers,carry,sum,digit,l; while(cin>>N) { for(intk=1; k<=n;k++) {MAXN=-1; memset (Array,0,sizeof(array)); memset (Answer,0,sizeof(answer)); for(num_integers=0;num_integers< -; num_integers++) {gets (buffer); if(strcmp (Buffer,"0")==0) Break; Len=strlen (buffer); if(len>maxn) MAXN=Len; for(intj=len-1, m=0; j>=0; j--) Array[num_integers][m++]=buffer[j]-'0'; } Carry=0; for(intI=0; i<maxn+2; i++) {sum=carry; for(intj=0; j<num_integers;j++) {sum+=Array[j][i]; Digit=sum%Ten; Carry=sum/Ten; Answer[i]=Digit; } } for(l=maxn+2; l>=0; l--) if(answer[l]!=0) Break; while(l>=0) {cout<<answer[l--]; } cout<<Endl; } } return 0;}
Addition operation of decimal large number