#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
string input;
getline(cin, input);
int t = input.find('E', 0);
string number = input.substr(0, t);
string exponent = input.substr(t + 1);
char num_sign = number[0];
char exp_sign = exponent[0];
number = number.substr(1);
exponent = exponent.substr(1);
t = number.find('.', 0);
string integer = number.substr(0, t);
string fraction = number.substr(t + 1);
int f = fraction.length();
int e = atoi(exponent.c_str());
if (num_sign == '-') cout << num_sign;
if (exp_sign == '+' && e >= f) {
cout << integer << fraction;
while (e > f) {
cout << '0';
e--;
}
} else if (exp_sign == '+' && e < f) {
cout << integer;
cout << fraction.substr(0, e);
cout << '.';
cout << fraction.substr(e);
} else if (exp_sign == '-') {
cout << "0.";
while (e - 1 > 0) {
cout << '0';
e--;
}
cout << integer << fraction;
}
cout << endl;
return 0;
}
【PAT甲级】1073. Scientific Notation (20)
最新推荐文章于 2022-09-19 20:06:51 发布