Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
终于AC了,借助Java BigDecimal,不知道有没有大神自己写算法过的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator