PTA Scientific Notation (20分)

释放无限光明的是人心,制造无边黑暗的也是人心,光明和黑暗交织着,厮杀着,这就是我们为之眷恋又万般无奈的人世间。

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=3e5+10;
vector<char> jg;
char t;
int fh,op[2],fg=1,in,tt;
int main(){
    while((t=getchar())!='\n'){
        if(t=='+'||t=='-')
            op[in++]=t;
        else if(t=='.')
            continue;
        else if(t=='E')
            fg=0;
        else{
            if(fg)
                jg.push_back(t);
            else
                fh=fh*10+t-'0';
        }
    }
    if(op[1]=='-')
        fh*=-1;
    tt=fh+1;
    if(tt<=0){
        while(tt++)
            jg.insert(jg.begin(), '0');
        jg.insert(jg.begin(), '.');
        jg.insert(jg.begin(), '0');
    }
    else{
        if(tt<jg.size())
            jg.insert(jg.begin()+tt, '.');
        else
            while(tt-jg.size())
                jg.push_back('0');
    }
    if(op[0]=='-')
        printf("-");
    for(int i=0; i<jg.size(); i++)
        printf("%c", jg[i]);
    printf("\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44170305/article/details/108401957
今日推荐