Sample Input
+1.23400E-03
Sample Output
0.00123400
思路:
模拟一下就可。
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
#define endl '\n'
typedef long long ll;
string str;
int main()
{
cin >> str;
int eq, sp;
for (int i = 0; i < str.size(); ++i)
{
if (str[i] == 'E')
eq = i;
}
int fq, fh;
if (str[0] == '+')
fq = 1;
else
fq = -1;
if (str[eq + 1] == '+')
fh = 1;
else
fh = -1;
int z = 0;
for (int i = eq + 2; i < str.size(); ++i)
z = z * 10 + str[i] - '0';
if (z == 0)
{
cout << "1" << endl;
return 0;
}
if (fq < 0)
cout << "-";
if (fh < 0)
{
cout << "0.";
while (z - 1)
{
cout << "0";
z--;
}
for (int i = 1; i < eq; ++i)
{
if (str[i] != '.')
cout << str[i];
}
}
else
{
int num = -1;
for (int i = 1; i < eq; ++i)
{
if (str[i] != '.')
{
cout << str[i];
num++;
}
if (num == z && i != eq - 1)
cout << ".";
}
while (z - num > 0)
{
cout <<"0";
z--;
}
}
return 0;
}