#include<bits/stdc++.h>
using namespace std;
struct Num {
string str;
int point;
Num(string & n) : str(n){
if(str[0] == '-')
cout << "-";
str = str.substr(1); // 自此忽略掉符号
int exp_idx = str.find('E');
auto index = stoi(str.substr(exp_idx + 1));
point = str.find('.'); // 题目的正则表达式保证一定含小数点
str.erase(exp_idx + str.begin(), str.end());
if(index == 0){ // 指数为0,则直接输出
cout << str << endl;
return;
}
str.erase(point, 1); // 去除掉小数点
if(index < 0) // 指数小于0,则小数点向左移动
point += index - 1;
else {
point = index - (exp_idx - 1 - point);
if(point < 0) { // 小数点向右移动,但不能使所有数位不能全部变成整数
str.insert(point + exp_idx - 1 + str.begin(), '.');
cout << str << endl;
return;
}
}
// cout << point << endl;
if(point <= 0) {
int n_p = abs(point);
for(int i = 0; i < n_p; ++i) {
cout << "0";
if(i == 0)
cout << ".";
}
cout << str << endl;
} else {
cout << str;
cout << string(point, '0') << endl;
}
};
};
int main() {
string str;
cin >> str;
Num num(str);
}
PAT甲级 1073 Scientific Notation
最新推荐文章于 2024-05-31 14:42:05 发布