码迷,mamicode.com
首页 > 其他好文 > 详细

poj1003 Hangover

时间:2014-08-23 01:00:19      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   for   

bubuko.com,布布扣

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.00
3.71
0.04
5.19
0.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 = 0;   
        int index = 2;     
        while (value < len)   
        {   
            value += 1.0/index;   
            index++;   
        }   
               
        return index-2;   
    }   
  
}  

 

poj1003 Hangover

标签:des   style   blog   http   color   java   os   io   for   

原文地址:http://www.cnblogs.com/bigjava/p/3930437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!