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 |
疯了完全没理由啊对于第1003题为什么这样是答案是错误的呢?? 我找了运行可以通过的答案,几乎没差别啊?? 求教大神啊 下面是我的答案: public class Main{ public static void main(String[] args){ String str; float c,sum = 0; int i; Scanner scanner = new Scanner(System.in); str = scanner.nextLine(); while(!str.equals("0.00")){ c = Float.valueOf(str).floatValue(); for(i=1;sum<c;i++){ sum = sum + 1f/(i+1); } System.out.printf("%d card(s)\n",i-1); str = scanner.next(); } } } 下面是测试可通过的代码: import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); String str; int maxCardNum = 0; while(cin.hasNext()) { str = cin.nextLine(); if(str.equals("0.00")) break; float len = Float.valueOf(str).floatValue(); maxCardNum = getCardNum(len); System.out.println(maxCardNum + " card(s)"); } } private static int getCardNum(float len) { float value = 0; int index = 2; while (value < len) { value += 1.0/index; index++; } return index-2; } } 这差在哪呢? Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator