10106 - Product



The Problem

The problem is to multiply two integers X, Y. (0<=X,Y<10250)

The Input

The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.

The Output

For each input pair of lines the output line should consist one integer the product.

Sample Input

12
12
2
222222222222222222222222

Sample Output

144
444444444444444444444444
大数相乘一直没有a过。今天看了一篇文章,心血来潮,a了这道题,有点小兴奋
#include<stdio.h>
#include<string.h>
int main()
{
	int  a[10001],b[10001],len1,len2,i,j,c[1001],k1,k2,k3;
	char st1[1000],st2[1000],st3[1000];
	while(scanf("%s%s",st1,st2)!=EOF)
	{
		k2=0;
		len1=strlen(st1);
		len2=strlen(st2);
		for(i=0;i<=len1-1;i++)
			a[i]=st1[len1-i-1]-'0';
		for(i=0;i<=len2-1;i++)
			b[i]=st2[len2-i-1]-'0';
		memset(c,0,sizeof(c));
		for(i=0;i<=len1-1;i++)
		{
			k2=0;
			for(j=0;j<=len2-1;j++)
			{
				c[i+j]+=a[i]*b[j];
				if(c[i+j]>=10)
				{
					c[i+j+1]+=c[i+j]/10;
					c[i+j]=c[i+j]%10;
				}

			}
		}
			len1+=len2;
			while(c[len1]==0&&len1!=0)
				len1--;
			if(len1==0)
				printf("0");
			else
			{
			for(i=len1;i>=0;i--)
				printf("%d",c[i]);
			}
			
			printf("\n");
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值