POJ 1001 & UVa 748 - Exponentiation in JAVA

之前用C++写过,各种辛酸泪.

今天用JAVA试了一下....(╯‵□′)╯  ┴─┴ 

谁用谁知道.

主要是算出来后要用.toPlainString.repalceAll(^0, "")去掉科学计数法和最前面的0.


import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner (new BufferedInputStream(System.in));
		BigDecimal N;
		
		while (cin.hasNext())
		{
			BigDecimal R = BigDecimal.valueOf(1);
			N = cin.nextBigDecimal();
			int n = cin.nextInt();
			R = N.pow(n).stripTrailingZeros();
			System.out.println(R.toPlainString().replaceAll("^0", ""));
		}
		
	}
}


你可能感兴趣的:(ACM,poj)