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

题意:

题目要求对给定的科学计数法进行解析,并且输出传统计数法表示的数字,要求正数不带正号,小数保留原来的后缀0个数。

题解:

先找到E的位置,然后计算出指数,再根据指数大小和E的位置输出结果,该补0补0,改有小数点的位置不能忘了小数点,因为就算指数是正数,也有可能结果还是小数。虽然起初考虑了,但是小数点点的位置算错了,测试点4就没过,之后发现了,是计算错误。

AC代码:

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
string a;
int main(){
cin>>a;
int l=a.length();
int e=-;
int zhi=;
for(int i=;i<l;i++){
if(a[i]=='E'){//找到E的位置
e=i;
i+=;
}
if(e!=-){//算出指数的大小
zhi=zhi*+a[i]-'';
}
}
int zuo=;//小数点往左边调还是右边调
if(a[e+]=='-') zuo=;
if(a[]=='-') cout<<'-';//是负数先输出负号
if(zuo==){//左调的情况
cout<<"0.";
for(int i=;i<=zhi-;i++){//在0.后面输出(指数-1)个0
cout<<"";
}
for(int i=;i<e;i++){//忽略.输出底数
if(a[i]=='.') continue;
else cout<<a[i];
}
}else{
if(zhi>=e-)
{
for(int i=;i<e;i++){//忽略.输出底数
if(a[i]=='.') continue;
else cout<<a[i];
}
for(int i=;i<=zhi-(e-);i++) cout<<'';//补0
}else{
for(int i=;i<e;i++){//测试点4仍会是小数,要在指数+3的地方输出.
if(i==zhi+) cout<<".";
if(a[i]=='.') continue;
else cout<<a[i];
}
}
}
return ;
}

PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)的更多相关文章

  1. PAT甲级——1073 Scientific Notation (20分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  2. PAT Advanced 1073 Scientific Notation (20 分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  3. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  4. 【PAT甲级】1073 Scientific Notation (20 分)

    题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...

  5. PAT甲题题解-1073. Scientific Notation (20)-字符串处理

    题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...

  6. PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)

    PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...

  7. C#版 - PAT乙级(Basic Level)真题 之 1024.科学计数法转化为普通数字 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. PAT Bas ...

  8. 1073. Scientific Notation (20)

    题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...

  9. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

随机推荐

  1. for循环中嵌套异步请求问题

    for循环中嵌套了异步请求会导致顺序错乱,用递归代替for循环,可以保证正常执行顺序:

  2. Oracle 新增数据 insert into整理

    一.普遍的方法:insert into 表名(id,name,age,status,字段N) values('id','name','age','status','字段N');   --建议用这个   ...

  3. 大小端示例-arm c51

    大小端系列文章https://blog.csdn.net/liming0931/article/details/100016425 MDK(Keil5,STM32F407)C语言: #include  ...

  4. Apollo简介及工作原理

    一.Apollo简介 1.Apollo是携程框架部门研发的分布式配置中心 2.集中化管理应用的不同环境和不同集群的配置 3.配置修改后能够实时推送到应用端 4.具备规范的权限.流程治理等特性 二.Ap ...

  5. LightOJ - 1246 - Colorful Board(DP)

    链接: https://vjudge.net/problem/LightOJ-1246 题意: You are given a rectangular board. You are asked to ...

  6. RestTemplate 使用中的几个问题

    Spring Boot使用RestTemplate消费REST服务的几个问题记录 我们可以通过Spring Boot快速开发REST接口,同时也可能需要在实现接口的过程中,通过Spring Boot调 ...

  7. D. Vasya and Triangle(思维, 三角形)

    传送门 题意: 给你 n, m, k, 问你是否存在一个三角形, 满足三角形的面积等于 n * m / k: 若存在, 输出YES, 且输出满足条件的三角形的三个坐标(答案有多种,则输出任意一种)   ...

  8. Codevs 1482 路线统计(矩阵乘法)

    1482 路线统计 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description N个节点的有向图, 求从start到finish刚好经过时 ...

  9. AttributeError: module 'tensorflow' has no attribute 'set_random_seed'

    anaconda3 python3.7 安装好tensorflow 后出现上面的问题,原因是安装的tensorflow版本是2.0的,所以使用以前的代码tensorflow中的函数不兼容.

  10. 1071 Speech Patterns (25)(25 分)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...