zoukankan      html  css  js  c++  java
  • 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.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;   
        }   
      
    }  
  • 相关阅读:
    阿里巴巴开源的Asynchronous I/O Design and Implementation
    maven 出现错误 -source 1.5 中不支持 diamond 运算符
    Kafka设计解析(六)- Kafka高性能架构之道
    Kafka设计解析(七)- Kafka Stream
    flink如何动态支持依赖jar包提交
    Hbase技术笔记
    windows环境:idea或者eclipse指定用户名操作hadoop集群
    HBase源码实战:BufferedMutator
    HBase工具:如何查看HBase的HFile
    HBase源码实战:CreateRandomStoreFile
  • 原文地址:https://www.cnblogs.com/bigjava/p/3930437.html
Copyright © 2011-2022 走看看