需要把情况考虑全了
比如后面的位数是比前面的位数多还是少啊
用了atoi(c.c_str())不知道为什么stoi不行
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
string a,b,c;
char one;
int wei1,wei2,now,two;
int main(){
cin >> a;
if(a[0]=='+') printf("");
else printf("-");
for(int i=1; i<a.length(); i++){
if(a[i] != '.' && a[i] != 'E'){
b += a[i];
}
else if(a[i] == '.'){
wei1 = i - 1;
}
if(a[i] == 'E'){
wei2 = i - 1 - wei1 - 1;
now = i;
break;
}
}
if(a[now+1]=='+') two = 1;
else two = 0;
bool key = false;
for(int i = now+2; i<a.length(); i++){
if(a[i] != '0' ) {
key = true;
c += a[i];
}
else if(key == true && a[i] == '0')
c += a[i];
}
int sum = atoi(c.c_str()); //用stoi会报错?不知道为什么。。。
if(two == 0){
int d = sum - wei1;
if(d < 0) {
d = wei1 - sum;
for(int i=0; i<b.length(); i++){
printf("%c",b[i]);
if(i == d-1) printf(".");
}
}
else {
printf("0.");
for(int i=0; i<d; i++) printf("0");
cout << b;
}
}
else if(two == 1){
int d = sum - wei2;
if(d>=0){
cout << b;
for(int i=0; i<d; i++) printf("0");
}
if(d<0){
d = wei2 - sum;
for(int i=0; i<b.length(); i++){
printf("%c",b[i]);
if(i == wei1+sum-1) printf(".");
}
}
}
return 0;
}