题目链接:
2 seconds
256 megabytes
standard input
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 aand b.
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.
Print the only line — the "simple exponential notation" of the given number x.
16
1.6E1
01.23400
1.234
.100
1E-1
100.
1E2 题意: 把给出的这个数用科学计数法法表示; 思路: 注意前导0,末尾的0,还有就是小数点的位置等; AC代码:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} //const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e6+10;
const int maxn=1005;
const double eps=1e-10; char s[N],ans[N]; int main()
{
scanf("%s",s); int len=strlen(s),pos=len,lastpos,cnt;
For(i,0,len-1)
{
if(s[i]=='.')
{
pos=i;
break;
}
}
//if(s[0]=='.')pos=0;
For(i,0,len-1)
{
if(s[i]>'0'&&s[i]<='9')
{
ans[0]=s[i];
ans[1]='.';
lastpos=i+1;
cnt=1;
for(int j=i+1;j<len;j++)
{
if(s[j]>='0'&&s[j]<='9')ans[++cnt]=s[j];
}
break;
}
}
for(int i=cnt ;i>=1;i--)
{
if(ans[i]=='0'||ans[i]=='.')cnt--;
else break;
}
for(int i=0;i<=cnt;i++)
{
printf("%c",ans[i]);
}
if(pos!=lastpos)
{
if(pos>lastpos)
{
printf("E%d",pos-lastpos);
}
else
{
printf("E%d",pos-lastpos+1);
}
}
printf("\n");
return 0;
}