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 |
Re:我的简洁JAVA答案In Reply To:我的简洁JAVA答案 Posted by:leiliang_2013 at 2010-10-28 10:24: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.hasNext()){ > BigDecimal R = in.nextBigDecimal(); > int n = in.nextInt(); > BigDecimal answer = R; > for(int i = 1; i < n; i ++) > answer = answer.multiply(R); > String ans = answer.toPlainString(); //toString is not enough here > if(ans.charAt(0) == '0' && ans.charAt(1)== '.') > ans = ans.substring(1, ans.length()); > if(ans.contains(".")) > { > boolean run = true; > int numOfZero = 0; > while(run) > { > if(ans.charAt(ans.length() - 1 - numOfZero) == '0') > numOfZero += 1; > else if(ans.charAt(ans.length() - 1 - numOfZero) == '.') > { > numOfZero += 1; > run = false; > } > else > run = false; > } > System.out.println(ans.substring(0, ans.length() - numOfZero)); > } > else > System.out.println(ans); > } > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator