A1073 Scientific Notation (20point(s))
字符串处理
题意
科学计数法输入,保留有效数字输出,包括末尾的0。
思路
字符串拼接,多试几次就行了。
Sample Input1:
+1.23400E-03
Sample Output1:
0.00123400
Sample Input2:
-1.2E+10
Sample Output2:
-12000000000
#include"bits/stdc++.h"
using namespace std;
int main(){
freopen("input.txt","r",stdin);
string s; cin >> s; // +1.23400E-03
string s1 = s.substr(1,1) + s.substr(3,s.find('E')-3);// 123400
string se = s.substr(s.find('E')+1,s.size()-s.find('E')-1);// 03
int te = stoi(se);//03
if(te < 0){
for(int i=0;i<abs(te);i++){
if(i == abs(te)-1) s1 = "0."+s1;
else s1 = "0"+s1;
}
}else{
int id = te+1; // '.' suppose to be
while(s1.size() < id) s1 += "0";
s1 = s1.substr(0,id) + '.' + s1.substr(id,s1.size()-id);
if(s1.back() == '.') s1 = s1.substr(0,s1.size()-1);
}
if(s[0] == '-') s1 = "-"+s1;
cout << s1 << endl;
}