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. C#调用一下CMD

    C#程序调用CMD执行命令   在windows环境下,命令行程序为cmd.exe,是一个32位的命令行程序,微软Windows系统基于Windows上的命令解释程序,类似于微软的DOS操作系统.输入 ...

  2. LSTM神经网络输入输出究竟是怎样的?

    LSTM图和词向量输入分析

  3. 如何修改host

    因不可抗拒的原因,有些网站会被q,但只是比较恶心的域名DNS污染,并不需要tiizi,修改hosts文件即可. 以 www.youneed.win 为例: 首先,进入目录:C:\Windows\Sys ...

  4. php 文件包含函数

    在实际开发中,常常需要把程序中的公用代码放到一个文件中,使用这些代码的文件只需要包含这个文件即可.这种方法有助于提高代码的重用性,给代码的编写与维护带来很大的便利.在PHP中, 有require.re ...

  5. HTML插入音频和视频:audio和video标签及其属性

    一.上传到第三方网站,然后引入例如视频上传到优酷网,然后得到代码 <iframe height=498 width=510 src='http://player.youku.com/embed/ ...

  6. 《挑战30天C++入门极限》 对C++中引用的补充说明(实例)

        对C++中引用的补充说明(实例) #include <iostream>    #include <string>    using namespace std;    ...

  7. docker安装postgresql

    1.在linux执行以下代码: docker run -p : -v /home/docker/postgresql/data:/var/lib/postgresql/data -e POSTGRES ...

  8. Python在windows平台的多版本配置

    Python在windows平台的多版本配置 快速阅读: ​ python在windows平台的环境变量以及多版本配置 ,以及pycharm如何安装包,以及安装包出错时如何排查. 1.python环境 ...

  9. mac编译Cpython

    源代码中有什么? CPython 源代码分发包含各种工具,库和组件.我们将在本文中探讨这些内容. 首先,我们将重点关注编译器.先从 git 上下载 Cpython 源代码. git clone htt ...

  10. JavaScript初探系列目录

    一  系列导航 结合各方面的参考资料,整理出来以下主要目录,供方便浏览查看 (一)初探系列           JavaScript初探系列(1)——基本概念 JavaScript初探系列(2)——数 ...