首页 > 代码库 > poj1003 Hangover
poj1003 Hangover
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.003.710.045.190.00
Sample Output
3 card(s)61 card(s)1 card(s)273 card(s)
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 = http://www.mamicode.com/0; int index = 2; while (value < len) { value += 1.0/index; index++; } return index-2; } }
poj1003 Hangover
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。