标签:ase case har memset span print %s cas include
#include<stdio.h>
#include<string.h>
int main()
{
int a[1010],b[1010],c[1010];
int n,k=1;
scanf("%d",&n);
while(n--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
char str1[1005],str2[1005];
scanf("%s%s",str1,str2); //把两个数当作字符串输入
int len1=strlen(str1),len2=strlen(str2);
int i,h=0;
for(i=len1-1; i>=0; i--)
a[h++]=str1[i]-‘0‘;
h=0;
for(i=len2-1; i>=0; i--)
b[h++]=str2[i]-‘0‘;
int d=len1>len2 ? len1 : len2;
int m=0;
for(i=0; i<d; i++)
{
c[i]=(a[i]+b[i]+m)%10;
m=(m+a[i]+b[i])/10; //用m来保存a[i]与b[i]的和是否大于十,以及是否要进一。
}
printf("Case %d:\n%s + %s = ",k++,str1,str2);
if(m==0)
{
for(i=d-1; i>=0; i--)
printf("%d",c[i]);
if(n)
printf("\n\n");
else
printf("\n");
}
else
{
printf("1");
for(i=d-1; i>=0; i--)
printf("%d",c[i]);
if(n)
printf("\n\n");
else
printf("\n");
}
}
return 0;
}
标签:ase case har memset span print %s cas include
原文地址:https://www.cnblogs.com/hbhdhd/p/10496320.html