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

Java double就能过,float 不行,无语

Posted by mid_winter at 2013-03-29 16:22:32 on Problem 2707
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int min1 = sc.nextInt();
			int max1 = sc.nextInt();
			int min2 = sc.nextInt();
			int max2 = sc.nextInt();
			
			if(min1==0&&min2==0&&max1==0&&max2==0){
				break;
			}
			
			if(min1>max1){
				int tmp = min1;
				min1 = max1;
				max1 = tmp;
			}

			if(min2>max2){
				int tmp = min2;
				min2 = max2;
				max2 = tmp;
			}
			double rate1 = (double)max1/min1;
			double rate2 = (double)max2/min2;	
			
			NumberFormat nf = NumberFormat.getPercentInstance();

			nf.setMaximumIntegerDigits(3);
			nf.setMinimumFractionDigits(0);

			nf.setRoundingMode(RoundingMode.DOWN);		
			double r = 0;
			if(rate1>rate2){
				r = (double) max2 / max1;
			}else{
				r = (double) min2 / min1;		
			}
			
			if(r<0.01){
				r = 0.01f;
			}
			
			if(r>1){
				r = 1;
			}
			System.out.println(nf.format(r));
		}
	}
}

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