1073. Scientific Notation (20)
来源:互联网 发布:python 时间精确度 编辑:程序博客网 时间:2024/05/16 19:12
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
一开始没注意到input 必然是+X.XXX格式,所以对+22.22这类情况也做了讨论,整体看起来有点长..
#include <stdio.h>#include <stdlib.h>int main(){char a[30000];char b[10000],c[10000];char signal[2]={0};int i,j=0,count,pos=-1,flag=0,flag1=0;gets(a);signal[0] = a[0];for(i=1;a[i]!='E';i++){if(a[i] == '.'){pos = i -1;}else{b[j] = a[i];j++;}}if(pos == -1){pos = j;}b[j] = 0;j = 0;signal[1] = a[++i];for(++i;a[i]!=0;i++){c[j] = a[i];j++;}c[j] = 0;count = atoi(c);if(signal[1] == '+'){if(signal[0] == '-'){printf("-");}pos +=count;i = 0;while(b[i] != 0){if(flag){printf("%c",b[i]);}else{if(b[i] !='0' || b[i+1] =='0' && i+1==pos){flag = 1;printf("%c",b[i]);}}i++;if(i == pos && b[i]!=0){printf(".");}}if( i < pos){while(i != pos){i++;printf("0");}}}if(signal[1] =='-'){if(signal[0] == '-'){printf("-");}pos -=count;if(pos <0){printf("0.");pos++;while(pos <=0){printf("0");pos++;}i = 0;while(b[i] != 0){printf("%c",b[i]);i++;}}else{if(pos == 0){printf("0.");}i = 0;while(b[i] != 0){printf("%c",b[i]);i++;if(i == pos){printf(".");}}}}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)
- 大数据环境平台DW部分目录路径(final)
- PHP时间戳,时间日期的处理
- 2016.7.18
- FileMapping
- 设计模式之中介者模式
- 1073. Scientific Notation (20)
- Shell脚本编程30分钟入门
- linux下生成.so文件和.a文件
- [LeetCode] 22.Generate Parentheses
- matlab绘制图像的灰度直方图
- jedis学习笔记【1】
- 几个相关系数:Pearson、Spearman、pointbiserialr、kendalltau
- xml文件的报错Failed to read schema document
- Apache Flink:详细入门