欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1073 Scientific Notation (20分)

程序员文章站 2022-07-15 10:30:17
...

1073 Scientific Notation (20分)

#include<string>
#include<math.h>
#include<iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int indexOfE = s.find('E');
	string baseNumber = s.substr(1, indexOfE - 1);
	int exp = stoi(s.substr(indexOfE + 1));
	int pointIndex = baseNumber.find('.');
	baseNumber.erase(pointIndex, pointIndex);
	if (exp < 0) {
		for (int i = 0; i < abs(exp); i++) {
			baseNumber = '0' + baseNumber;
		}
		baseNumber.insert(1, ".");
	}
	else {
		int pointIndex = 1 + exp;
		if (pointIndex < baseNumber.size()) {
			baseNumber.insert(pointIndex, ".");
		}
		else {
			while (pointIndex > baseNumber.size()) {
				baseNumber += '0';
			}
		}
	}
	if (s[0] == '-') {
		baseNumber = '-' + baseNumber;
	}
	cout << baseNumber << endl;
}