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 }

原文地址:https://www.cnblogs.com/blue-lin/p/11431667.html

时间: 2024-10-16 05:20:11

PAT_A1073#Scientific Notation的相关文章

pat1073. Scientific Notation (20)

1073. Scientific Notation (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+

PAT 1073. Scientific Notation (20)

1073. Scientific Notation (20) 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

PAT1073. Scientific Notation

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 i

1073. Scientific Notation (20)

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

PAT(A) 1073. Scientific Notation (20)

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

Excel scientific notation issue

? ? This is a known issue, you can find more in internet. Excel will treat text(can display with number) more than 11 numbers, it will convert to scientific notation display. It is not an issue now, but if your text content length is more than 15, th

PAT 1073 Scientific Notation[字符串处理][科学记数法]

1073 Scientific Notation(20 分) 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 exa

[PAT] 1073 Scientific Notation (20 分)Java

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 lea

1073 Scientific Notation

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 lea