Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于AC了,借助Java BigDecimal,不知道有没有大神自己写算法过的

Posted by fuhaiwei at 2014-08-19 22:16:56 on Problem 1001 and last updated at 2014-08-19 22:27:48
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNextLine()) {
			String[] split = in.nextLine().split(" +");
			if (split.length != 2) {
				return;
			}
			BigDecimal bd = new BigDecimal(split[0]);
			int n = Integer.parseInt(split[1]);
			String result = bd.pow(n).toPlainString();
			if (result.contains(".")) {
				result = result.replaceFirst("0+$", "");
			}
			if (result.endsWith(".")) {
				result = result.substring(0, result.length() - 1);
			}
			if (result.startsWith("0.")) {
				result = result.substring(1);
			}
			System.out.println(result);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator