代码来自https://www.liuchuo.net/archives/551
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
//#include<stdafx.h>
using namespace std;
int main()
{
string s;
cin >> s;
int i = 0;
int j = 0;
while (s[i] != 'E')
i++;//找到e的位置
string number = s.substr(1, i - 1);//两个有用的函数
string e = s.substr(i + 2);
int ee = stoi(s.substr(i + 2));
if (s[0] == '-') cout << "-";
if (s[i + 1] == '-')//如果e是负的
{
cout << "0.";
for (j = 1; j < ee; j++) cout << 0;
for (j = 0; j < number.length(); j++)
{
if (number[j] != '.')
cout << number[j];
}
}
else//如果e是正的
{
cout << number[0];
//两种情况 +1.23456E+02 123.456
// +1.2E+02 120
int cc = ee - number.length() + 2;
if (cc >= 0)
{
for (j = 2; j < number.length(); j++)
cout << number[j];
for (j = 0; j < cc; j++) cout << 0;
}
else
{
int cnt;
int k;
for (j = 2, cnt = 0; j < number.length() && cnt < ee; j++, cnt++) cout << number[j];
if (j == number.length()) {
for (k = 0; k < ee - cnt; k++) cout << '0';
}
else {
cout << '.';
for (k = j; k < number.length(); k++) cout << number[k];
}
}
}
return 0;
}