cf 619c 科学记数法1

Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

 Status

Description

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.

Sample Input

Input
16
Output
1.6E1
Input
01.23400
Output
1.234
Input
.100
Output
1E-1
Input
100.
Output
1E2


代码如下:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define M 1000005
char s[M],ss[M];
using namespace std;
int main()
{
    int i,k,j,m,k1,k2;
    while(~scanf("%s",&s))
    {
        m=strlen(s);
        for(i=0; i<m; i++)
        {
            if(s[i]=='.')//标记小数点的位置
            {
                k1=i;
                break;
            }
            else k1=m;
        }

        for(i=0; i<m; i++)
        {
            if(s[i]>'0'&&s[i]<='9')
            {
                ss[0]=s[i];
                ss[1]='.';
                k=1;
                k2=i+1;
                for(j=i+1; j<m; j++)
                {if(s[j]>='0'&&s[j]<='9')
                    ss[++k]=s[j];
                }
                break;
            }
        }
        for(i=k; i>=1; i--)//去掉多余的0和小数点
        {
            if(ss[i]=='0'||ss[i]=='.')
                k--;
            else break;
        }
        for(i=0; i<k+1; i++)
            printf("%c",ss[i]);
        if(k1>k2)
        {
            printf("E%d",k1-k2);
        }
        else if(k1<k2)
            printf("E%d",k1-k2+1);
        printf("\n");
    }
    return 0;
}




全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:28
25届每天都在焦虑找工作的事情0offer情绪一直很低落硬撑着面了一个岗位岗位有应酬的成分面试的时候hr给我出各种场景题问的问题比较犀利&nbsp;有点压力面的感觉感觉有点回答不上来本来就压抑的情绪瞬间爆发了呢一瞬间特别想哭觉得自己特别没用没绷住掉眼泪了事后想想觉得自己挺有病的&nbsp;真的破大防了
喜欢唱跳rap小刺猬...:我觉得没关系吧,之前有一次面试leader给我压力面,我顶住了压力,结果入职的时候发现组里氛围很差,果断跑路。其实从面试就能大概看出组的情况,面试体验好的组倒是不一定好,但是面试体验不好的组。。。就很难说
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务