PAT_A1073#Scientific Notation

Posted blue-lin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT_A1073#Scientific Notation相关的知识,希望对你有一定的参考价值。

Source:

PAT A1073 Scientific Notation (20 分)

Description:

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent‘s signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent‘s absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

Keys:

  • 字符串处理

Code:

 1 #include<cstdio>
 2 #include<string>
 3 #include<iostream>
 4 using namespace std;
 5 
 6 int main()
 7 
 8 #ifdef ONLINE_JUDGE
 9 #else
10     freopen("Test.txt", "r", stdin);
11 #endif // ONLINE_JUDGE
12 
13     string s;
14     cin >> s;
15     int pos = s.find(E);
16     string fra = s.substr(0,pos);
17     int exp = atoi(s.substr(pos+1).c_str());
18     fra.erase(2,1);
19     if(exp > 0)
20     
21         int len = exp+3-fra.size();
22         if(len>0)
23             for(int i=1; i<len; i++)
24                 fra.insert(fra.end(),0);
25         else
26             fra.insert(fra.begin()+exp+2,.);
27     
28     else
29     
30         for(int i=0; i>exp; i--)
31             fra.insert(fra.begin()+1,0);
32         fra.insert(fra.begin()+2,.);
33     
34     if(fra[0]==+)
35         fra.erase(0,1);
36     cout << fra;
37 
38     return 0;
39 

 

以上是关于PAT_A1073#Scientific Notation的主要内容,如果未能解决你的问题,请参考以下文章

1073 Scientific Notation

1073 Scientific Notation

PAT甲级——1073 Scientific Notation (20分)

PAT(A) 1073. Scientific Notation (20)

[PAT] 1073 Scientific Notation (20 分)Java

1073 Scientific Notation