• 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;
            }
        }
    }
     
  • 相关阅读:
    EOS之session的数据获取
    c# 数据库操作之ACCESS
    基础之创建与导出
    dotNET5的MVC页面传值方式总结
    dotNET开发之MVC中Controller返回值类型ActionResult方法总结
    C# 计算农历日期方法(2021版)
    普通邮箱设置客户端授权码并开启stmp服务以及关于QQ邮箱“命令顺序不正确。 服务器响应为:Error: need EHLO and AUTH first !”问题全指导
    13 张图,深入理解 Synchronized
    Springboot 注解大全
    python中的print()函数的学习-1
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9052281.html
Copyright © 2020-2023  润新知