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 ...
随机推荐
- jquery中ajax跨域加载
今天学习ajax跨域加载,先来一段代码,异步加载的链接是爱奇艺的开源,我直接拿来用作测试 <!DOCTYPE html> <html lang="en"> ...
- Newtonsoft.Json 自定义序列化器---时间
IsoDateTimeConverter _IsoDateTimeConverter = new IsoDateTimeConverter() { DateTimeFormat = "yyy ...
- LOJ P10065 北极通讯网络 题解
每日一题 day39 打卡 Analysis 1.当正向思考受阻时,逆向思维可能有奇效. 2.问题转化为:找到最小的d,使去掉所有权值>d的边之后,连通支的个数<k; 3.定理:如果去掉所 ...
- am335x system upgrade rootfs for dhcpcd cross compile(十三)
dhcpcd移植 [目的] 移植dhcpcd的目是在AM335X开发板上使用dhcp功能,获取WAN口设备的IP,并且可以通过参数指定其matric,matric值越小,其优先级越高.如设备可以以太网 ...
- element-ui upload上传组件问题记录
element-ui upload上传组件遇到的问题
- raycaster选取捕获obj模型&&选中高亮代码
目录 raycaster选取捕获obj模型&&选中高亮代码 raycaster关键代码 选中高亮代码 obj整体上色 raycaster选取捕获obj模型&&选中高亮代 ...
- UOJ#316. 【NOI2017】泳池 动态规划,Berlekamp-Massey,Cayley-Hamilton定理
原文链接www.cnblogs.com/zhouzhendong/p/UOJ316.html 题解 首先,我们将答案转化成最大矩形大小 \(\leq k\) 的概率 减去 \(\leq k-1\) 的 ...
- Python 程序打包成 exe 可执行文件
Python 程序打包工具 Python 是一个脚本语言,被解释器解释执行.它的发布方式: .py 文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装 Python 并且安装依赖 ...
- [提权]sudo提权复现(CVE-2019-14287)
2019年10月14日, sudo 官方在发布了 CVE-2019-14287 的漏洞预警. 0x00 简介 sudo 是所有 unix操作系统(BSD, MacOS, GNU/Linux) 基本集成 ...
- pymongo helper
import pymongo import click # 数据库基本信息 db_configs = { 'type': 'mongo', 'host': '127.0.0.1', 'port': ' ...