http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?cid=4034&pid=8
C++版本一
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,ans;
int a;
char str[500];
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
while(~scanf("%s%d",str,&n)){
int len=strlen(str);
int flag=len;
if(str[0]=='-'){
printf("-");
str[0]='0';
}
int flag0=-1;
for(int i=0;i<len;i++){
if(str[i]=='.'){
flag=i;
}
if(str[i]!='0'&&str[i]!='.'&&flag0==-1){
flag0=i;
}
}
for(int i=0;i<=20;i++){
str[len+i]='0';
}
str[len+21]='\0';
printf("%c",str[flag0]);
int cnt=1;
if(cnt<n)printf(".");
t=flag0;
while(cnt<n){
flag0++;
if(str[flag0]!='.'){
cnt++;
printf("%c",str[flag0]);
}
}
if(flag-t<0)
printf("e%d",flag-t);
else if(flag-t>0)
printf("e%d",flag-t-1);
printf("\n");
}
//cout << "Hello world!" << endl;
return 0;
}
C++版本二
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
char s[150];
int main(){
int y;
while(~scanf("%s%d",&s,&y)){
int c=0,i=0,index=0,dian,len=strlen(s);
while(s[i]!='.'&&i<len)i++;
dian=i;
while(s[index]=='0'||s[index]=='.'){
index++;
}
if(dian>index)c=dian-index-1;
else c=dian-index;
printf("%c",s[index]);
if(y>1)printf(".");
for(i=1;i<y;i++){
index++;
if(s[index]=='.'){
y++;
continue;
}
if(s[index]=='\0')printf("0");
else printf("%c",s[index]);
}
printf("e%d\n",c);
memset(s,0,sizeof(s));
}
return 0;
}