您的位置:首页 > 编程语言 > Java开发

Bull Math(java大数相乘)

2014-10-03 14:18 211 查看
Link:点击打开链接

Problem:

Bull Math

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 12950Accepted: 6674
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

Source

USACO 2004 November
import java.util.*;

import java.io.*;

import java.math.*;

import java.text.*;

public class Main{

public static void main(String[] args)

{

BigInteger x,y,ans;

Scanner cin=new Scanner(System.in);

while(cin.hasNext())

{

x=cin.nextBigInteger();

y=cin.nextBigInteger();

ans=x.multiply(y);

System.out.println(ans);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: