PAT 甲级 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 分) (根据科学计数法写出数)的更多相关文章
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT Advanced 1073 Scientific Notation (20 分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...
- 【PAT甲级】1073 Scientific Notation (20 分)
题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...
- PAT甲题题解-1073. Scientific Notation (20)-字符串处理
题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...
- PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)
PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...
- C#版 - PAT乙级(Basic Level)真题 之 1024.科学计数法转化为普通数字 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. PAT Bas ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
随机推荐
- HTTP头部
10-URI的基本格式以及与URL的区别 HTTP连接的常见流程 从TCP编程上看HTTP请求处理 长连接与短连接 补充一下代理的知识 什么是正向代理,什么是反向代理? 想在外部公网访问公司内部局域网 ...
- mysql跨表删除多条记录
Mysql可以在一个sql语句中同时删除多表记录,也可以根据多个表之间的关系来删除某一个表中的记录. 假定我们有两张表:Product表和ProductPrice表.前者存在Product的基本信息, ...
- python会缓存小的整数和短小的字符
经过测试,python会缓存的小整数的范围是 [-5, 256] # True a = 1 b = 1 print(a is b) # True a = "good" b = &q ...
- Set的常用实现类HashSet和TreeSet
Set HashSet public static void main(String[] args) { //不可以重复 并且是无序的 //自然排序 从A-Z //eqauls从Object继 ...
- .net web api 返回的是xml
var result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(dto2) ...
- TPCH 22条SQL语句分析
使用TPC-H进行性能测试,需要有很多工作配合才能获得较高性能,如建立索引,表数据的合理分布(使用表空间和聚簇技术)等.本文从查询优化技术的角度,对TPC-H的22条查询语句和主流数据库执行每条语句对 ...
- [转载]JSON WEB TOKEN,简单谈谈TOKEN的使用及在C#中的实现
https://www.cnblogs.com/chenwolong/p/Token.html
- Spring入门(二)——DI
1. DI Dependency Injection,依赖注入.当对象里有属性或对象的时候,就需要为这些属性或对象赋值 2. 流程 这里介绍两种方式 set方法 注解方式 2.1 set方法 Bean ...
- [Windows] 输入字符间距变宽
今天在输入时,不会到误触到哪里,输入的字符间距变得很宽,如下图: 最后找到原因是不小心同时按下了 Shift+Space(空格),进入全角模式,就会导致输入的字符间距变宽 想要恢复,再按一次 shif ...
- centos7磁盘分区、格式化、挂载
1.分区:a. 查看磁盘分区表: # fdisk -l b. 查看指定磁盘分区表: # fdisk -l /dev/sdb c. 分区命令: fdisk /dev/sdb 常用命令: n:创建新分区 ...