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 [+-][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 file 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


提交代码

科学计数法。

 1 #include<cstdio>
 2 #include<stack>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<stack>
 6 #include<set>
 7 #include<map>
 8 using namespace std;
 9 string trans(string s){
10     int i=1;
11     while(i<s.length()){//有效数位
12         if(s[i]==‘E‘){
13             break;
14         }
15         i++;
16     }
17     int index=++i;//指数符号位
18
19     //cout<<index<<endl;
20
21     i++;//指数开始
22     int exp=0;
23     //确定指数
24     while(i<s.length()&&s[i]==‘0‘){//去掉前0
25         i++;
26     }
27
28     //cout<<i<<endl;
29
30     while(i<s.length()){//指数计算
31         exp*=10;
32         exp+=s[i]-‘0‘;
33         i++;
34     }
35
36     //cout<<exp<<endl;
37
38     string ss;
39     if(s[index]==‘-‘){
40         i=exp-1;
41         ss="0.";
42         while(i){
43             i--;
44             ss=ss+‘0‘;
45         }
46         ss=ss+s[1];
47         for(i=3;s[i]!=‘E‘;i++){
48             ss=ss+s[i];
49         }
50     }
51     else{//
52         ss=s[1];
53         for(i=3;s[i]!=‘E‘&&exp;i++,exp--){
54             ss=ss+s[i];
55         }
56         if(s[i]==‘E‘){
57             while(exp){
58                 ss=ss+‘0‘;
59                 exp--;
60             }
61         }
62         else{
63             ss=ss+‘.‘;
64             while(s[i]!=‘E‘){
65                 ss=ss+s[i];
66                 i++;
67             }
68         }
69     }
70     if(s[0]==‘-‘){
71         ss=‘-‘+ss;
72     }
73     return ss;
74 }
75 int main(){
76     //freopen("D:\\INPUT.txt","r",stdin);
77     string s;
78     cin>>s;
79     //cout<<s<<endl;
80     cout<<trans(s)<<endl;
81     return 0;
82 }
时间: 2024-08-27 17:31:34

pat1073. Scientific Notation (20)的相关文章

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

PAT甲级——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 at lea

PAT (Advanced Level) 1073. Scientific Notation (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; char s[100000]; int p;

PAT甲题题解-1073. Scientific Notation (20)-字符串处理

题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #define POSITIVE 1 #define NEGATIVE 2 using names

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

[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