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
分析:字符串处理题,按题意改就行了。代码改了好多次。。。可能只有我自己能看懂了吧。。20分的题debug了半小时。。。
1 /**
2 * Copyright(c)
3 * All rights reserved.
4 * Author : Mered1th
5 * Date : 2019-02-24-16.27.04
6 * Description : A1073
7 */
8 #include<cstdio>
9 #include<cstring>
10 #include<iostream>
11 #include<cmath>
12 #include<algorithm>
13 #include<string>
14 #include<unordered_set>
15 #include<map>
16 #include<vector>
17 #include<set>
18 using namespace std;
19
20 int main(){
21 #ifdef ONLINE_JUDGE
22 #else
23 freopen("1.txt", "r", stdin);
24 #endif
25 string s,ans="";
26 cin>>s;
27 if(s[0]=='-'){
28 printf("-");
29 }
30 s.erase(s.begin());
31 int i,len=s.length(),k,p;
32 for(i=0;i<len;i++){
33 if(s[i]>='0' &&s[i]<='9'){
34 ans+=s[i];
35 }
36 else if(s[i]=='.'){
37 k=i; //记录小数点位置
38 continue;
39 }
40 else if(s[i]=='E') {
41 p=i; //记录E的位置
42 break;
43 }
44 }
45 bool flag=true;
46 if(s[i+1]=='-') flag=false;
47 s.erase(i,2); //删除E和指数符号
48 string e="";
49 for(i;i<len-1;i++){
50 e=e+s[i];
51 }
52 int E=stoi(e);
53 if(flag==false){
54 printf("0.");
55 for(int j=0;j<E-1;j++){
56 printf("0");
57 }
58 cout<<ans;
59 }
60 if(flag==true){
61 if(p-k-1==E){
62 cout<<ans;
63 }
64 else if(p-k-1<E){
65 cout<<ans;
66 for(int j=0;j<E-1;j++){
67 printf("0");
68 }
69 }
70 else{
71 int a=(p-k-1)-E+2,m;
72 for(m=0;m<a;m++){
73 printf("%c",ans[m]);
74 }
75 printf(".");
76 for(;m<ans.size();m++){
77 printf("%c",ans[m]);
78 }
79 }
80 }
81 return 0;
82 }