#include<stdio.h>
#include<string.h>
int main()
{
int a[22] = { 0 }, b[ 22 ] = { 0 };
int i, j, lensa, lensb, len, c, count ;
char sa[22], sb[22];
scanf("%s%s",&sa,&sb);
while (sa[0] != '0'||sb[0]!='0')
{
lensa = strlen(sa); lensb = strlen(sb);
j = 0;
for (i = lensa - 1; i >= 0; i--)
a[j++] = sa[i] - '0';
j = 0;
for (i = lensb - 1; i >= 0; i--)
b[j++] = sb[i] - '0';
j = 0;
if (lensa >= lensb) len = lensa;
else len = lensb;
c = 0;
count = 0;
for (i = 0; i < len; i++)
{
a[i] = a[i] + b[i] + c;
if (a[i] >= 10)
{
a[i] = a[i] % 10;
c = 1;
count++;
}
else
c = 0;
}
if (c > 0)
{
a[len] = c;
len++;
}
printf("%d carry operation(s)\n", count);
count=0;
scanf("%s%s", &sa, &sb);
for(i=0;i<22;i++)
{
a[i]=0;
b[i]=0;
}
}
return 0;
}
NBUOJ1451
最新推荐文章于 2024-11-15 09:21:36 发布