PAT 1073. Scientific Notation (20)
来源:互联网 发布:路径规划算法的例子 编辑:程序博客网 时间:2024/05/17 02:22
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(){int i;char str[1000000],r[1000000],exsign,exponent[1000000],ans[1000000];memset(str,0,sizeof(str));memset(r,0,sizeof(r));memset(exponent,0,sizeof(exponent));memset(ans,0,sizeof(ans));scanf("%s",str);int lenstr=strlen(str);if(str[0]=='-')printf("-");int cntr=0;for(i=1;str[i]!='E'&&i<lenstr;i++) //保存底数在r[]中r[cntr++]=str[i];i++;//指向指数的符号exsign=str[i];i++; //指向指数的第一个数据位int cntex=0;for(;i<lenstr;i++) //保存指数在exponent[]中exponent[cntex++]=str[i];int sum=0;for(i=0;i<cntex;i++)sum=sum*10+exponent[i]-'0';//puts(r);//puts(exponent);//printf("%c&&&%d",exsign,sum);int cntans=0;if(exsign=='-'){for(i=cntr-1;i>=0;i--){if(r[i]!='.')ans[cntans++]=r[i];}for(i=0;i<sum-1;i++) //左边再补上sum-1个0ans[cntans++]='0';ans[cntans++]='.';ans[cntans++]='0';for(i=cntans-1;i>=0;i--)printf("%c",ans[i]);printf("\n");}if(exsign=='+'){if(sum<cntr-2){ans[cntans++]=r[0];for(i=2;i<sum+2;i++){ //第三位下标实际上是2!ans[cntans++]=r[i];}ans[cntans++]='.';for(i=sum+2;i<cntr;i++)ans[cntans++]=r[i];for(i=0;i<cntans;i++)printf("%c",ans[i]);printf("\n");}if(sum>=cntr-2){for(i=0;i<cntr;i++){if(r[i]!='.')ans[cntans++]=r[i];}for(i=0;i<sum-(cntr-2);i++)ans[cntans++]='0';for(i=0;i<cntans;i++)printf("%c",ans[i]);printf("\n");}} return 0;}
- 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 1073. Scientific Notation
- PAT 1073. Scientific Notation
- 【PAT】1073. Scientific Notation
- pat 1073. Scientific Notation
- PAT (Advanced) 1073. Scientific Notation (20)
- PAT Advanced Level 1073. Scientific Notation (20)
- PAT A 1073. Scientific Notation (20)
- PAT甲级练习1073. Scientific Notation (20)
- PAT甲级1073. Scientific Notation (20)
- 自定义AlertDialog布局
- 第4章 从目标到结果,成为执行达人
- 共享池之八:软解析、硬解析、软软解析 详解一条SQL在library cache中解析涉及的锁
- Android系统目录下 各jar包作用
- Python decorate 函数
- PAT 1073. Scientific Notation (20)
- Swift:高级架构、流水线深度、内存延迟 转载
- Android Loader详解一:概述
- hdu 1686 Oulipo(KMP)
- Android Loader详解二:使用加载器
- 链接
- Rotate Image
- 2014川大复试c语言
- Android Loader详解三:重启与回调