PAT A1073. Scientific Notation (20)
来源:互联网 发布:pywin32 知乎 编辑:程序博客网 时间:2024/05/21 06:01
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 file 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-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#define Max 100001using namespace std;int main(){char a[Max],b[Max],c[Max];int z=-1,f=0,bf=0,cf=0,y=-1;int m,n=0,x,d,nm=0;int num[Max];scanf("%s",a);if(a[0]=='-') printf("-");m=a[0];for(int i=3;i<strlen(a);i++){if(a[i]=='E') { x=i-3;d=i;f=1; }else if(f==0){b[bf++]=a[i];}else if(f==2&y!=-1){c[cf++]=a[i];}else if(f==1){f=2;if(a[i]=='-'){y=0;}else if(a[i]='+'){y=1;}}}for(int i=0;i<strlen(a);i++){if(a[i]>='0'&&a[i]<='9')num[nm++]=a[i]-'0';if(a[i]=='E') break;}for(int i=0;i<cf;i++){n=n*10+(c[i]-'0');}if(y==0){n=n+bf-1;printf("0.");for(int i=0;i<=n-nm;i++) printf("0");for(int i=0;i<nm;i++) printf("%d",num[i]);printf("\n");}else if(y==1){if(n>bf){n=n-bf; for(int i=0;i<nm;i++) printf("%d",num[i]);for(int i=0;i<n;i++) printf("0");}else {n=bf-n;for(int i=0;i<nm-n;i++) {printf("%d",num[i]); z=i;} if(z<nm-1) printf(".");for(int i=nm-n;i<nm;i++) printf("%d",num[i]);}printf("\n");}system("pause");return 0;}
- 【PAT】A1073. Scientific Notation (20)
- PAT A1073. Scientific Notation (20)
- PAT-A1073. Scientific Notation (20)(模拟)
- A1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation(20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- 【PAT】1073. Scientific Notation (20)
- Pat 1073 PAT 1073. Scientific Notation (20)
- PAT (Advanced) 1073. Scientific Notation (20)
- PAT Advanced Level 1073. Scientific Notation (20)
- PAT A 1073. Scientific Notation (20)
- PAT(甲级)Scientific Notation (20)
- PAT甲级练习1073. Scientific Notation (20)
- 适配器模式(Adapter Pattern)- 最易懂的设计模式解析
- iOS修行---Auto Layout学习1
- ajax提交json数据并使用Springmvc接收实例
- ORA-15025: could not open disk "/dev/asm***"
- 搭建SSH三大框架WEB项目过程(Struts2.3+Hibernate4.3+Spring4.1)
- PAT A1073. Scientific Notation (20)
- Dagger2
- ruby on rails 常用的记录
- db2中关于递归(with)的使用
- 缓存图片解决方案(来自stackoverflow)
- Sass-@for,@while,@each
- AndroidStudio2.2.3 的使用
- 1.模型评估的方法与性能度量
- 在Java项目中如何使用log4j和slf4j实现日志打印