标签:
#include <stdio.h>
#include <string.h>
int main()
{
char a[101],b[101];
int i,j,k,cas,count=1,num2,num3;
scanf("%d",&cas);
getchar();
while (cas--)
{
int c[100000]= {0};
scanf("%s %s",a,b);
num2=strlen(a);
num3=strlen(b);
if (strcmp(a,"0")==0||strcmp(b,"0")==0)
{
printf("Case %d:\n",count);
printf("%s * %s = 0\n",a,b);
count++;
}
else
{
for (i = 0; i < num2; i++)
{
for (j = 0; j < num3; j++)
{
c[i+j]+=(a[num2-i-1]-‘0‘)*(b[num3-j-1]-‘0‘);//核心
k=i+j;
while (c[k]>=10)
{
c[k+1]+=c[k]/10;
c[k]%=10;
k++;
}
}
}
i=9999;
num2=i;
while (c[i]==0)
{
i--;
num2 = i;//判断该得数的位数
}
printf("Case %d:\n",count);
count++;
printf("%s * %s = ",a,b);
for (i = num2; i >= 0; i--)
{
printf("%d",c[i]);
}
printf("\n");
}
if (cas>=1)
{
printf("\n");
}
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/SSYYGAM/p/4214021.html