Try Again

Coderfroces 691 C. Exponential notation

C. Exponential notation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a positive decimal number x.

Your task is to convert it to the "simple exponential notation".

Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b.

Input

The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.

Output

Print the only line — the "simple exponential notation" of the given number x.

Examples
Input
16
Output
1.6E1
Input
01.23400
Output
1.234
Input
.100
Output
1E-1
Input
100.
Output
1E2
模拟题,但是情况都点多,自己还是太弱,代码估计显得冗长
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
string sf,sl,b;
char a[1000006];
void solve(char *a)
{
    sf="";sl="";b="";
    bool flag=false;
    bool del=false;
    for(int i=0;a[i]!='\0';i++)
    {
        if(a[i]=='.')
        {
            del=true;
            break;
        }
        if(a[i]=='0' && !flag) continue;
        else 
        {
            sf+=a[i];
            flag=true;
        }
    }
    if(sf.size()>0)
    {
        flag=false;
        for(int i=sf.size()-1;i>=0;i--)
        {
            if(sf[i]=='0' && flag==false) continue;
            else
            {
                b+=sf[i];
                flag=true;
            }
        }
        reverse(b.begin(),b.end());
    }
    if(del==true)
    {
        int len=strlen(a);
        flag=false;
        for(int i=len-1;i>=0;i--)
        {
            if(a[i]=='.') break;
            if(a[i]=='0' && !flag) continue;
            else
            {
                sl+=a[i];
                flag=true;
            }
        }
        reverse(sl.begin(),sl.end());
    }
    if(sf.size()>0)
    {
        if(sf.size()==1 && sl.size()==0)
        {
            cout<<sf<<endl;
        }
        if(sf.size()==1 && sl.size()!=0)
        {
            cout<<sf<<"."<<sl<<endl;
        }
        if(sf.size()>1 && sl.size()==0)
        {
            cout<<sf[0];
            if(b.size()==1) cout<<"E"<<sf.size()-1<<endl;
            else
            {
                cout<<".";
                for(int i=1;i<b.size();i++)
                cout<<b[i];
                cout<<"E"<<sf.size()-1<<endl;
            }
        }
        if(sf.size()>1 && sl.size()!=0)
        {
            cout<<sf[0]<<".";
            for(int i=1;i<sf.size();i++)
                cout<<sf[i];
            cout<<sl<<"E"<<sf.size()-1<<endl;
        }
    }
    else
    {
        int pos=1;
        int k=sl.size(),vis;
        for(int i=0;i<k;i++)
        {
            if(sl[i]=='0') pos++;
            else
            {
                vis=i;
                break;
            }
        }
        if(k-1==vis)
        {
            cout<<sl[vis]<<"E-"<<pos<<endl;
        }
        else
        {
            cout<<sl[vis]<<".";
            for(int i=vis+1;i<k;i++)
                cout<<sl[i];
            cout<<"E-"<<pos<<endl;
        }
    }
}
int main()
{
    scanf("%s",a);
    solve(a);
    return 0;
}

 

posted @ 2017-07-22 12:12  十年换你一句好久不见  阅读(169)  评论(0编辑  收藏  举报