标签:notation Exponential point int str Output Input include 模拟
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<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int main(){
string str;
cin>>str;
int len=str.length() ;
int l=-1,r=len-1,num=0,point=-1;
for(int i=0;i<len;i++){//找到.的位置
if(str[i]=='.'){
point=i;
break;
}
}
if(point==-1)// 式子中没有 .
point=len;
for(int i=0;i<len;i++){//从左边找第一个不是0 的数
if(str[i]!='0'&&str[i]!='.'){
l=i;
break;
}
}
for(int i=len-1;i>=0;i--){//从右边找第一个不是0 的数
if(str[i]!='0'&&str[i]!='.'){
r=i;
break;
}
}
//cout<<point<<endl;
if(l==-1)
cout<<"0"<<endl;//没有不是0 的数
else{
if(point>l)
num=point-l-1;
else
num=point-l;//负数
cout<<str[l];
if(l!=r)//要是只有一个数,就不用输出 .
cout<<".";
for(int i=l+1;i<=r;i++){
if(str[i]!='.')//原来那个.不输出
cout<<str[i];
}
if(num!=0)//阶数要是0 ,连E都不输出
cout<<"E"<<num<<endl;
}
return 0;
}
标签:notation,Exponential,point,int,str,Output,Input,include,模拟 来源: https://blog.csdn.net/red_red_red/article/details/88426879
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。