当前位置: 首页> 科技> 互联网 > 商贸有限公司_网站定制开发前期要有一定的规划_软件开发流程八个步骤_seo快速推广窍门大公开

商贸有限公司_网站定制开发前期要有一定的规划_软件开发流程八个步骤_seo快速推广窍门大公开

时间:2025/9/10 4:38:09来源:https://blog.csdn.net/2401_88085478/article/details/144161356 浏览次数:2次
商贸有限公司_网站定制开发前期要有一定的规划_软件开发流程八个步骤_seo快速推广窍门大公开

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

 题目大意:题目给出科学计数法的格式的数字A,形式为:[+-][1-9].[0-9]+E[+-][0-9],要求输出普通数字表示法的A,并保证所有有效位都被保留,包括末尾的0,比如样例1.

分析:先统计指数的大小,不妨设指数大小为t。

如果指数t等于0,则直接输出源字符串;

指数t小于0,则需要把小数点向前移动t位;

指数t大于0,则需要把小数点向后移动t位。注意小数点移动后,可能还有小数部分,需要继续输出;或者小数点移动到末尾了,还没有到达实际的位置。这两个需要特别判断一下。

最后注意不能输出 “123.” 这种答案,应该输出 “123”

#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;#define ll long long
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endlint main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testchar s[10010];scanf("%s",s);int flag,len=strlen(s);if(s[0]=='-')printf("-");//负数先输出负号int t=0,f=1;flag=0;for(int i=1;i<len;++i)//先提取指数{if(flag){if(s[i]=='-')f=-1;else if(s[i]!='+')t=t*10+s[i]-'0';}if(s[i]=='E')flag=1;}if(t==0)//指数等于0{for(int i=1;s[i]!='E';++i)printf("%c",s[i]);}else if(f==-1)//指数小于0{printf("0.");//说明原来的数字是一个小数for(int i=1;i<t;++i)//这里一定会有若干个前导零printf("0");for(int i=1;s[i]!='E';++i)if(s[i]!='.')printf("%c",s[i]);}else//指数大于0{int j=0;printf("%c",s[1]);for(int i=3;s[i]!='E';++i){if(j==t)printf(".%c",s[i]),j++;//小数点移动到位置后,仍然存在小数部分else printf("%c",s[i]),j++;}for(;j<t;++j)//如果小数点还没移动到位置printf("0");//说明它后面还有若干个0}printf("\n");#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

关键字:商贸有限公司_网站定制开发前期要有一定的规划_软件开发流程八个步骤_seo快速推广窍门大公开

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: