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)