zoukankan      html  css  js  c++  java
  • Codeforces Round #362 B. Barnicle JAVA高精度

    B. Barnicle
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

    Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.

    Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

    Input

    The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.

    a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

    Output

    Print the only real number x (the desired distance value) in the only line in its decimal notation.

    Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.

    Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).

    Examples
    Input
    8.549e2
    Output
    854.9
    Input
    8.549e3
    Output
    8549
    Input
    0.33e0
    Output
    0.33
    JAVA使我又吃了一鲸;
    不说了,见代码
    import java.math.*;
    import java.util.*;
     
     
    public class Main {
           public static void main(String[] args)
           {
              Scanner cin = new Scanner (System.in); 
              BigDecimal a = cin.nextBigDecimal();//可以读入指数呦
              a = a.stripTrailingZeros();//清除末尾的0
              System.out.println(a.toPlainString());
             //toPlainString    返回不带指数字段的此 BigDecimal 的字符串表示形式
           }
    }
                  
          
    View Code
  • 相关阅读:
    Spring源码学习之容器的基本实现(一)
    面向对象设计原则
    简单易懂带你了解红黑树
    简单易懂带你了解二叉树
    单例模式
    原形模式
    数组与链表
    记一次解决postgresql数据库内存泄露的问题
    记一次排查CPU高的问题
    react ts 设置paths 和 声明非@types的模块
  • 原文地址:https://www.cnblogs.com/cshg/p/5676763.html
Copyright © 2011-2022 走看看