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的什么地方判断错了

Posted by litchi at 2005-09-06 02:04:03 on Problem 1003
总是结果wrong answer
感谢了
已经提交了10多次都没通过
郁闷呀
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
  static float[] cardLength = new float[1000];

  static private int cacuMinCards(float length){
    for (int i = 2; ;i++)
    {
      if((length - (float)1/i) <= 0)
        return i - 1;
      length = length - (float)1/i;
    }
  }

  public static void main(String[] args) {
    for (int i = 0;; i++){
      try {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        cardLength[i] = Float.parseFloat(br.readLine());
        if (0 == cardLength[i]) break;
      }
      catch (Exception e) {
        break;
      }
    } 
    for (int i = 0; i < cardLength.length; i++) {
      if (0 == cardLength[i]) break;
      System.out.println(cacuMinCards(cardLength[i]) + " card(s)");
    }
  }
}

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