Bull Math
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 14252 |
|
Accepted: 7350 |
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
Source
Usaco 2004 November
original title link: http://poj.org/problem?id=2389
large number multiplication, only one set of data!
AC Code:
Import Java.math.biginteger;import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner s c = new Scanner (system.in), while (Sc.hasnext ()) {BigInteger a = Sc.nextbiginteger (); BigInteger B = Sc.nextbiginteger (); System.out.println (a.multiply (b));}}}
AC Code 2:
#include <stdio.h> #include <string.h> #define MAX 220int Main () {char S1[max],s2[max]; int A1[max],a2[max],p[2*max];; int i,j,len_1,len_2; memset (a1,0,sizeof (A1)); Memset (a2,0,sizeof (A2)); memset (P,0,sizeof (p)); Gets (S1); Gets (S2); Len_1=strlen (S1); Len_2=strlen (S2); for (j=0,i=len_1-1;i>=0;i--) {a1[j++]=s1[i]-' 0 '; } for (j=0,i=len_2-1;i>=0;i--) {a2[j++]=s2[i]-' 0 '; } for (i=0;i<len_1;i++) {for (j=0;j<len_2;j++) {p[i+j]+=a1[i]*a2[j]; }} for (i=0;i<max*2;i++) {if (p[i]>9) {P[I+1]+=P[I]/10; p[i]%=10; }} int start=0; for (i=max*2-1;i>=0;i--) {if (start) {printf ("%d", p[i]); } else if (P[i]) {printf ("%d", p[i]); Start=1; }} if (!start) printf ("0"); return 0;}
POJ 2389 Bull Math (large number multiplication, or Java good)