这个代码需要化简,
#include<iostream>
using namespace std;
char output[10010];
int lastNumberIndex=-1;
int pointPos=-1;//the index of the last number which before the point
int pow;
bool afterPoint=false;
bool numberPositive=true;
bool powPositive=true;
bool powStart=false;
bool hasShowPoint=false;
int main()
{
char temp;
temp=cin.get();
if(temp=='-')
{
numberPositive=false;
}
while(true)
{
temp=cin.get();
if(powStart==false)
{
if(temp=='E')
{
powStart=true;
continue;
}
if(temp=='.')
{
afterPoint=true;
continue;
}
output[++lastNumberIndex]=temp;
if(!afterPoint)
{
pointPos++;
}
}
else
{
if(temp=='\n')
{
break;
}
if(temp=='-')
{
powPositive=false;
continue;
}
if(temp=='+')
{
continue;
}
pow=pow*10+temp-'0';
}
}
//display
if(!numberPositive)
{
cout<<'-';
}
if(powPositive)
{
for(int i=0;i<=lastNumberIndex;i++)
{
if(i>pointPos)
{
if(pow>0)
{
pow--;
}
else if(!hasShowPoint)
{
cout<<'.';
hasShowPoint=true;
}
}
cout<<output[i];
}
while(pow>0)
{
cout<<'0';
pow--;
}
hasShowPoint=true;
}
else
{
if(pointPos<pow)
{
int diff=pow-pointPos;
cout<<"0.";
hasShowPoint=true;
for(int i=0;i<diff-1;i++)
{
cout<<0;
}
for(int i=0;i<=lastNumberIndex;i++)
{
cout<<output[i];
}
}
else
{
pointPos=pointPos-pow;
for(int i=0;i<=lastNumberIndex;i++)
{
cout<<output[i];
if(i==pointPos&&!hasShowPoint)
{
hasShowPoint=true;
cout<<".";
}
}
}
}
cout<<endl;
}