天天看點

HDU 1063 Exponentiation (高精度)

JAVA大法好~~

import java.util.Scanner;
import java.math.BigInteger;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		BigDecimal a, b;
		while (sc.hasNextBigDecimal()) {  //判斷輸入類型是否滿足 以提供循環輸入
			a = sc.nextBigDecimal();
			n = sc.nextInt();
			b = new BigDecimal("1");
			for (int i = 1; i <= n; ++i) {
				b = b.multiply(a);

			}
			b = b.stripTrailingZeros(); // 去後導零
			String str = b.toPlainString(); // 避免科學計數
			if (str.startsWith("0.")) {  //去除前導
				str = str.substring(1);
			}
			System.out.println(str);

		}

	}
}