1073. Scientific Notation (20)
来源:互联网 发布:淘宝二维码用微信打开 编辑:程序博客网 时间:2024/06/05 09:45
1073. Scientific Notation (20)
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<stdio.h>#include<string.h>int main(){ char s[100000]; int n,m,i,j,k,q; gets(s); for(i=0;s[i]!='E';i++); k=i; if(s[i+1]=='-') q=1; if(s[i+1]=='+') q=2; m=strlen(s)-i; if(m==6) { n=(s[i+2]-'0')*1000+(s[i+3]-'0')*100+(s[i+4]-'0')*10+(s[i+5]-'0'); } if(m==5) { n=(s[i+2]-'0')*100+(s[i+3]-'0')*10+(s[i+4]-'0'); } if(m==4) { n=(s[i+2]-'0')*10+(s[i+3]-'0'); } if(m==3) { n=(s[i+2]-'0'); } if(n!=0) { if(q==2) { if(n<k-3) { if(s[0]=='-') printf("%c",s[0]); printf("%c",s[1]); for(i=2;i<n+2;i++) printf("%c",s[i+1]); if(i+1!=k) printf("."); for(i=n+3;s[i]!='E';i++) printf("%c",s[i]); } if(n>=k-3) { if(s[0]=='-') printf("%c",s[0]); for(i=1;s[i]!='E';i++) { if(s[i]!='.') printf("%c",s[i]); } for(j=k-3;j<n;j++) printf("0"); } } if(q==1) { if(s[0]=='-') printf("%c",s[0]); printf("0."); for(i=0;i<n-1;i++) printf("0"); for(i=1;s[i]!='E';i++) { if(s[i]!='.') printf("%c",s[i]); } } } if(n==0) { if(s[0]=='-') printf("%c",s[0]); for(i=1;s[i]!='E';i++) printf("%c",s[i]); } return 0;}
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 安卓获取手机联系人
- mysql可视化工具-navicat的下载和使用
- Hibernate关系映射级别注解(多对多单向外键关联、多对多双向外键关联)
- 2017.10.14一试
- 文本挖掘
- 1073. Scientific Notation (20)
- QNX程序的键盘输入与控制台输出
- python 求 牛顿插值法中的差商表
- 在使用RBO的情况下,出现两条或两条以上的执行路径的等级值相同的情况下,如何调整执行计划?
- 数组扩容
- Android 进程保活--无限播放音乐
- 记录自己的大数据学习之路
- 冒泡排序
- Matlab GUI登录界面(edit,pushbutton),键盘按下事件