PAT乙级-1024 科学计数法(Pat grade b-1024 scientific counting method)

科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9][0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指数部分的正负号即使对正数也必定明确给出。

.

现以科学计数法的格式给出实数 A,请编写程序按普通数字表示法输出 A,并保证所有有效位都被保留。

输入格式:

每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 A。该数字的存储长度不超过 9999 字节,且其指数的绝对值不超过 9999。

输出格式:

对每个测试用例,在一行中按普通数字表示法输出 A,并保证所有有效位都被保留,包括末尾的 0。

输入样例 1:

+1.23400E-03
结尾无空行

输出样例 1:

0.00123400
结尾无空行

输入样例 2:

-1.2E+10
结尾无空行

输出样例 2:

-12000000000
结尾无空行

代码:

代码来自:https://www.cnblogs.com/gh110/p/12158233.html

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BigDecimal s = new BigDecimal(in.readLine());
        System.out.println(s.toPlainString());
    }
}
————————

Scientific counting is a convenient method used by scientists to represent large or small numbers. It satisfies the regular expression [+ -] [1-9] [0-9] + E [+ -] [0-9] +, that is, the integer part of the number has only one digit, and the decimal part has at least one digit. Even if the sign of the number and its exponential part is positive, it must be clearly given.

.

Now the real number a is given in the format of scientific counting method. Please write a program to output a according to the ordinary digital representation, and ensure that all significant bits are reserved.

Input format:

Each input contains one test case, that is, a real number a represented by scientific counting method. The storage length of this number shall not exceed 9999 bytes, and the absolute value of its exponent shall not exceed 9999.

Output format:

For each test case, output a in one line according to the ordinary digital representation, and ensure that all significant bits are reserved, including 0 at the end.

Input example 1:

+1.23400E-03
结尾无空行

Output example 1:

0.00123400
结尾无空行

Input example 2:

-1.2E+10
结尾无空行

Output example 2:

-12000000000
结尾无空行

code:

代码来自:https://www.cnblogs.com/gh110/p/12158233.html

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BigDecimal s = new BigDecimal(in.readLine());
        System.out.println(s.toPlainString());
    }
}