zoukankan      html  css  js  c++  java
  • e-olymp Problem11 Big accuracy

    传送门:点我

    Big accuracy

    The rational fraction m/n is given. Write it in the decimal notation with k digits after the decimal point.

    Input

    Three numbers mnk are written in one line. 0 < mn ≤ 1000 ≤ k ≤ 1000.

    Output

    Print k digits after the decimal point of the given number.

    Time limit 1 second
    Memory limit 64 MiB
    Input example #1
    1 2 3
    
    Output example #1
    0.500

    题意:给你N,M,K,求N/M ,保留K位。
    本题有点小坑的地方是,K等于0的时候是取整数部分,保留K位是直接扔掉后面的,不需要四舍五入。
    JAVA代码:
    import java.text.DecimalFormat;
    import java.util.*;
    import java.io.*;
    import java.math.BigDecimal;
    import java.math.BigInteger;
    import java.util.Arrays;
    import java.util.InputMismatchException;
    
    public class Main 
    {    
      public static void main (String[] argv) 
      {
          new Main();
      }
      boolean test = false;
      public Main(){
          FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
          //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));
          Scanner input = new Scanner(System.in);
          BigDecimal x = input.nextBigDecimal();
          BigDecimal y = input.nextBigDecimal();
          int k = input.nextInt();
          if(k == 0){
              BigDecimal ans = x.divide(y,1,BigDecimal.ROUND_DOWN);
              int answer = ans.intValue();
              System.out.println(answer);
          }//如果只需要整数部分,就直接取int
          else{
              BigDecimal ans = x.divide(y,k,BigDecimal.ROUND_DOWN);
              System.out.println(ans);
          }//保留K位,并且不需要四舍五入
          input.close();
      }
      static class FastReader
        {
            BufferedReader br;
            StringTokenizer st;
            public FastReader(BufferedReader in)
            {            
                br = in;
            }
     
            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        String line = br.readLine();
                        if (line == null || line.length() == 0) return "";
                        st = new StringTokenizer(line);
                    }
                    catch (IOException  e)
                    {
                        return "";
                        //e.printStackTrace();
                    }
                }
                return st.nextToken();
            }
     
            int nextInt()
            {
                return Integer.parseInt(next());
            }
     
            long nextLong()
            {
                return Long.parseLong(next());
            }
     
            double nextDouble()
            {
                return Double.parseDouble(next());
            }
     
            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    return "";
                    //e.printStackTrace();
                }
                return str;
            }
        }
    }
     
  • 相关阅读:
    FEniCS 1.1.0 发布,计算算术模型
    Piwik 1.10 发布,增加社交网站统计
    淘宝褚霸谈做技术的心态
    CyanogenMod 10.1 M1 发布
    Druid 发布 0.2.11 版本,数据库连接池
    GNU Gatekeeper 3.2 发布
    Phalcon 0.9.0 BETA版本发布,新增大量功能
    EUGene 2.6.1 发布,UML 模型操作工具
    CVSps 3.10 发布,CVS 资料库更改收集
    Opera 移动版将采用 WebKit 引擎
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9052281.html
Copyright © 2011-2022 走看看