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 ... 
随机推荐
- vue3 RFC初尝试
			由于vue3.x还没有正式发布,所以可以通过安装包vue-function-api提前尝试 npm install vue-function-api --save main.js import Vue ... 
- Thinkphp远程代码执行 payload汇总
			Thinkphp 5.0.22http://192.168.1.1/thinkphp/public/?s=.|think\config/get&name=database.usernameht ... 
- Memcached 与 Redis 区别
			一.问题: 数据库表数据量极大(千万条),要求让服务器更加快速地响应用户的需求. 二.解决方案: 1.通过高速服务器Cache缓存数据库数据 2.内存数据库 ( ... 
- AtCoder Grand Contest 006 题解
			传送门 \(A\) 咕咕 const int N=105; char s[N],t[N];int n; inline bool eq(R int k){fp(i,1,k)if(s[n-k+i]!=t[ ... 
- SpringBoot整合ElasticSearch:基于SpringDataElasticSearch
			0.注意事项 SpringDataElasticSearch可能和远程的ElasticSearch版本不匹配,会宝座 版本适配说明:https://github.com/spring-projects ... 
- 蚂蚁金服财富技术部,诚招Java研发工程师。校招内推!!!
			蚂蚁金服财富技术部,诚招Java研发工程师. 团队是蚂蚁金服财富技术部核心团队,支持亿级互联网交易清算,在这里不仅能学习到先进的互联网技术,也能了解许多终身受益的金融知识. 内推对象 2020届毕业生 ... 
- Git的使用(1) —— 版本库
			1. 简介 Git作为一个分布式版本控制系统,其优点是不需要一直连接远端版本库就可以使用. 故其为实现分布版本控制专门设计了一整套的存储区间和语句,用来实现. (1) 本地版本库:建立在本机磁盘上的文 ... 
- C前序遍历二叉树Morris Traversal算法
			首先来递归算法,简单易懂: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef ... 
- Traverse an expression tree and extract parameters
			Traverse an expression tree and extract parameters I think as you've said that using ExpressionVis ... 
- 如何在团队中做好Code Review
			一.Code Review的好处 想要做好Code Review,必须让参与的工程师充分认识到Code Review的好处 1.互相学习,彼此成就 无论是高手云集的架构师团队,还是以CURD为主的业务 ... 
