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;
            }
        }
    }
     
  • 相关阅读:
    aspnet_Membership_SetPassword
    FlipView使用
    结构之法字符串及链表的探索编程之美第3章
    window和linux下svn的使用
    【算法导论第13章】红黑树
    【算法导论】第16章贪心算法
    【算法导论】第15章动态规划
    ubuntu11.04下myeclipse开发环境的搭建(jdk6+tomcat6+myeclipse8.0+mysql)
    【matlab】在vc6.0中调用matlab中的正态分布产生随机数
    gnome/gtk+开发环境搭建
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9052281.html
Copyright © 2011-2022 走看看