PAT A1073 Scientific Notation (20分)

阅读: 评论:0

PAT A1073 Scientific Notation (20分)

PAT A1073 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.

输入
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.

输出
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.

样例输入
+1.23400E-03

样例输出
0.00123400

代码

#include <cstdio>int main () {char str[10010];int a[10010], i, j, num = 1, n = 0, t = 0;scanf("%s", str);bool f = false;if(str[0] == '-')printf("-");a[0] = str[1] - '0';for(i = 3; str[i] != 'E'; i++) {a[num++] = str[i] - '0';}if(str[i + 1] == '-')f = true;for(j = i + 2; str[j] != ''; j++) {if(str[j] == '0' && t == 0)continue;n = n * 10 + (str[j] - '0');t = 1;}if(f && n > 0){		//负指数printf("0.");for(i = 1; i < n; i++)printf("0");for(i = 0; i < num; i++) {printf("%d", a[i]);}printf("n");		}else {					//正指数for(i = 0; i < num; i++) {printf("%d", a[i]);if(i == n && n < num - 1)printf(".");}if(n > num)		for(i = 0; i <= n - num; i++)printf("0");printf("n");}return 0;
}

本文发布于:2024-02-01 16:32:07,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170677632837966.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:PAT   Scientific   Notation
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23