PAT 甲级 1073 Scientific Notation
作者:
自由基
,
2021-07-28 20:02:12
,
所有人可见
,
阅读 270
参考算法笔记
输入样例
+1.23400E-03
输出样例
0.00123400
C++代码
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int N = 10010;
char s[N];
int main( ) {
scanf("%s", s);
int len = strlen(s);
if ( s[0] == '-' ) cout << "-";
int pos = 0;
while ( s[pos] != 'E' ) pos++;
int exp = 0;
for ( int i = pos+2; i < len; i++ ) {
exp = exp * 10 + ( s[i] - '0' );
}
if ( exp == 0 ) {
for ( int i =1; i < pos; i++ ) {
cout << s[i];
}
}
if ( s[pos+1] == '-' ) {
cout << "0.";
for ( int i=0; i < exp - 1; i++ ) {
cout << 0;
}
cout << s[1];
for ( int i = 3; i < pos; i++ ) {
cout << s[i];
}
}
else {
for ( int i=1; i < pos; i++ ) {
if ( s[i] == '.' ) continue;
cout << s[i];
if ( i == exp + 2 && pos - 3 != exp ) {
cout << ".";
}
}
for ( int i=0; i < exp - ( pos - 3); i++ ) {
cout << 0;
}
}
return 0;
}