本题用字符串的方式求解,往后往前移动小数点的时候稍微有点绕,边测试边修改代码及即可
AC代码
#include <stdio.h>
int main(){
char str[10001];
int flag = 0;//标志位
gets(str);
if(str[0]=='-')
printf("-");
int i=0,j;
while(str[i]!='E'){
i++;
}
int exp = 0;//指数
for(j=i+2;str[j]!='\0';j++){
exp = exp*10+(str[j]-'0');
}
if(str[i+1]=='-'){ //说明是小数
printf("0.");
for(j=0;j<exp-1;j++){
printf("0");
}
printf("%c",str[1]);
for(j=3;j<i;j++){
printf("%c",str[j]);
}
}else{
printf("%c",str[1]);
for(j=3;j<i;j++){
if(j-2<=exp){
printf("%c",str[j]);
}else if(j-2==exp+1){
printf(".%c",str[j]);
flag = 1;
}else{
printf("%c",str[j]);
}
}
if(flag == 0){
for(j=i-3;j<exp;j++){
printf("0");
}
}
}
}