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

Re:我的简洁JAVA答案

Posted by cuihailong at 2011-01-14 11:05:50 on Problem 1001
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:
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