hdu 1002.A + B Problem II 解题报告

时间:2021-05-26 20:59:23

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002

题目意思:就是大整数加法。

  两年几前做的,纯粹是整理下来的。

  

 #include <stdio.h>
#include <string.h> #define max 1010
char a[max], b[max]; int main()
{
int i, k, s, c, T, len1, len2;
scanf("%d", &T);
for (k = ; k < T; k++)
{
int A[max] = {}, B[max] = {};
scanf("%s %s", &a, &b);
len1 = strlen(a);
len2 = strlen(b);
for (i = ; i < len1; i++)
A[i] = a[len1-i-] - '';
for (i = ; i < len2; i++)
B[i] = b[len2-i-] - '';
c = ;
for (i = ; i < max; i++)
{
s = A[i] + B[i] + c;
A[i] = s % ;
c = s / ;
}
printf("Case %d:\n%s + %s = ", k+, a, b);
for (i = max-; i >= ; i--)
{
if (A[i])
break;
}
for ( ; i >= ; i--)
printf("%d", A[i]);
printf("\n");
if (k < T - )
printf("\n");
}
return ;
}