大整数加法
Sample Input
20 20 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Sample Output
88888888888888888888
#include<stdio.h>
void main()
{
int m,n,i,j=0,d,min,a[3005]={0},b[3005]={0},sum[3010]={0};
scanf("%d %d",&m,&n);
min=m>n?n:m;
for(i=m-1;i>=0;i--)scanf("%d",&a[i]);
for(i=n-1;i>=0;i--)scanf("%d",&b[i]);
for(i=0;i<min;i++)d=a[i]+b[i],sum[j++]+=d%10,sum[j]=d/10;
while(!sum[j])j--;
d=sum[j],sum[j]=d%10,sum[j+1]=d/10;
if(m>n)for(i=min;i<m;i++)d=sum[i]+a[i],sum[i]=d%10,sum[i+1]=d/10;
else for(i=min;i<n;i++)d=sum[i]+b[i],sum[i]=d%10,sum[i+1]=d/10;
j=m>n?m:n;
while(!sum[j])j--;
for(i=j;i>=0;i--)printf("%d",sum[i]);
printf("\n");
}