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
思路
其实最讨厌做这类找规律题…
没啥好技巧就是缕清思路 考虑各种状况 找规律 这个还算简单
#include<bits/stdc++.h>
using namespace std;
int data[10000];
int main()
{
string s;
cin >> s;
int flag1,flag2,i,e,len;
flag1=(s[0]=='-'?-1:1);//数的正负
i=0;
e=0;len=0;//e是指数,len是E前面所有数字的长度
while(s[i]!='E'){
if(s[i]>='0'&&s[i]<='9'){
data[len++]=s[i]-'0';//先把E前的数据存起来,这部分是一定要输出的
}
i++;
}
flag2=(s[++i]=='-'?-1:1);//指数的正负
i++;
for(i;i<s.length();i++)//存一下指数大小
e=e*10+s[i]-'0';
if(flag1<0)
cout << "-";
if(flag2>0){
for(int i=0;i<len;i++){
cout << data[i];
if(i+1<len&&i==e)
cout << ".";
}
if(e>len-1){
int zeros=e-len+1;
while(zeros--)
cout << "0";
}
}
else{
if(e)
cout << "0.";
int zeros=e-1;
while(zeros--)
cout << "0";
for(int i=0;i<len;i++)
cout << data[i];
}
}