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
Copy
16
output
1.6E1
input
Copy
01.23400
output
1.234
input
Copy
.100
output
1E-1
input
Copy
100.
output
1E2

C.指数计数法

时间限制2秒

空间限制256mb

输入:正常输入

输出:正常输出

给定一个正的十进制数x。


您的任务是将其转换为“简单的指数表示法”。

 x = a·10b,其中1 ≤ a < 10,然后在一般的情况下,“简单的指数符号”看起来像“aEb”。如果b等于零,则应跳过“Eb”。如果a是整数,则应写成无小数点数字。A和B也不应该出现额外的零。


输入:
唯一的一行包含正的十进制数x。行的长度不会超过10^6。请注意,您给出的数字太多,所以不能使用标准的内置数据类型“float”、“double”和其他。

输出:
输出给定数字X的“简单指数记数法”。

样例:

输入
Copy
16
输出
1.6E1
输入
Copy
01.23400
输出
1.234
输入
Copy
.100
输出
1E-1
输入
Copy
100.
输出
1E2

C++程序:

# include<iostream>
# include<cstdio>
# include<cmath>
using namespace std;
double x,a,z,d[7];
int b,n,c;
int main()
{
cin>>x;
if(x>=1)
for(c=0;c<=6;c++)
{
d[c]=pow(10,c);
if(x<d[c])
{
a=x/d[c-1];
b=c-1;
break;
}
}
else if(x<=-1)
for(c=0;c<=6;c++)
{
d[c]=pow(10,c);
d[c]=-d[c];
if(x>d[c])
{
a=x/d[c-1];
a=-a;
b=c-1;
break;
}
}
else if(x<1&&x>0)
for(c=0;c<=6;c++)
{
d[c]=pow(10,c);
z=1/d[c];
if(x>z)
{
z=1/d[c-1];
a=x/z;
b=c-1;
if(a>0.1)
{
a*=10;
b-=1;
}
break;
}
}
else if(x<0&&x>-1)
for(c=0;c<=6;c++)
{
d[c]=pow(10,c);
d[c]=-d[c];
z=1/d[c];
if(x>z)
{
a=x/z;
a=-a;
b=c-1;
if(a<-0.1)
a*=10;
break;
}
}
if(b!=0)
  cout<<a<<"E"<<b<<endl;
else
  cout<<a<<endl;
return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值