1073 Scientific Notation (20 分)字符串处理——科学计数法

给定一个科学计数法表示的数,要求将其转换为常规表示并保持所有有效位,包括尾随零。输入和输出都是字符串,需要处理正负号、小数点位置和指数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目

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 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-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

解题思路

  题目大意: 给一个使用科学计数法表达的数,然后将概述转换成普通表达方式,该数据小数点后必有一位,数据格式为[±][1-9].[0-9]+E[±][0-9]+,要求保留数据有效位。
  解题思路: 数据位的长度最长为9999,显然需要用字符串来处理,而不是任何浮点型。由于题目给出了明确的数据格式,因此,根据字符串定义格式,以及科学计数法的定义去还原数据即可——
  1. 第一位记录正负值,负值需要在结果前加“-”符号,正值不需要加“+”;
  2. 第二位到E之间的数据是数据的有效位,除去小数点,统计即可;
  3. E后第一位是系数的正负值,该值决定了小数点往左移还是往右移;
  4. 最后几位是系数,取出来转换成整型即可。
  在字符串处理完之后,根据获取的有效位和系数进行还原即可。

/*
** @Brief:No.1073 of PAT advanced level.
** @Author:Jason.Lee
** @Date:2019-01-21
** @Solution: Accepted!
*/
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值