POJ 2389 Bull Math (multiply by large number)

Source: Internet
Author: User

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

Description

Bulls is 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 is correct. Help him check the Bulls ' answers. Read in the positive integers (no more than-digits each) and compute their product. Output it as a normal number (with no extra leading zeros).

FJ asks 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 lines

Sample Input

111111111111111111111111

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 (multiply by large number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.