码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2389 Bull Math(大数相乘)

时间:2015-11-03 10:35:54      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

Bull Math
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13920   Accepted: 7192

Description

Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls‘ answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros). 

FJ asks that you do this yourself; don‘t use a special library function for the multiplication.

Input

* Lines 1..2: Each line contains a single decimal number.

Output

* Line 1: The exact product of the two input lines

Sample Input

11111111111111
1111111111

Sample Output

12345679011110987654321











#include<stdio.h>
#include<string.h>
int main()
{
char a[45],b[45];
int s[90];
while(scanf("%s%s",a,b)!=EOF)
{
int i,j,k,s1,s2;
s1=strlen(a);
s2=strlen(b);
for(i=0; i<s1+s2; i++)
s[i]=0;
for(i=0; i<s1; i++)
for(j=0; j<s2; j++)
{
s[i+j+1]=s[i+j+1]+(a[i]-‘0‘)*(b[j]-‘0‘);
}
for(i=s1+s2-1; i>=0; i--)
if(s[i]>=10)
{
s[i-1]=s[i-1]+s[i]/10;
s[i]=s[i]%10;
}
i=0;
while(s[i]==0)
i++;
for(; i<s1+s2; i++)
printf("%d",s[i]);
printf("\n");
}
return 0;
}









POJ 2389 Bull Math(大数相乘)

标签:

原文地址:http://www.cnblogs.com/-lgh/p/4932227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!