PAT甲级——A1073 Scientific Notation
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
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str, f1, num1, num2, f2, num3, res = "";
cin >> str;
int nDot, E, Exp = ;
f1 = str[];
nDot = str.find('.');
num1 = str[nDot - ];//第一位数字
E = str.find('E');
num2.assign(str.begin() + nDot + , str.begin() + E);//小数点后面的数字
f2 = str[E + ];
num3.assign(str.begin() + E + , str.end());//指数
for (int i = ; i < num3.length(); ++i)//计算指数
Exp = Exp * + num3[i] - '';
if (f1 == "-")
res += "-";
if (f2 == "-")
{
res += "0.";
res.insert(res.end(), Exp - , '');//中间插入0
}
else if (f2 == "+")
{
if (num2.length() <= Exp)//小数位不足,则直接末尾加0;
num2.insert(num2.end(), Exp - num2.length(), '');
else//小数位多余幂次,则小数点后移
num2.insert(num2.begin() + Exp, , '.');
}
res += num1 + num2;
cout << res << endl;
return ;
}
PAT甲级——A1073 Scientific Notation的更多相关文章
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT A1073 Scientific Notation (20 分)——字符串转数字
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- A1073. Scientific Notation
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_A1073#Scientific Notation
Source: PAT A1073 Scientific Notation (20 分) Description: Scientific notation is the way that scient ...
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...
随机推荐
- WriteFile
从R3 ,到磁盘 1:kernel32 WriteFile 1) 挺惊讶的,符号好使了, 前面大概4条判断,根据句柄判断要写到什么地方,一共有4个地方可能要去, stdin stdout s ...
- window下apache2.2配置多个tomcat使用不同二级域名,共用80端口
思路:分3步, 1,安装apache服务器httpd-2.2.25-win32-x86-no_ssl.msi,安装tomcat 2,配置tomcat默认访问的项目,配置apache服务器 3,测试 第 ...
- WebApi路由机制详解
随着前后端分离的大热,WebApi在项目中的作用也是越来越重要,由于公司的原因我之前一直没有机会参与前后端分离的项目,但WebApi还是要学的呀,因为这东西确实很有用,可单独部署.与前端和App交互都 ...
- PHP出现报警后需要修改 date.timezone 的值(php.ini)
PHP调试的时候出现了警告: It is not safe to rely on the system解决方法,其实就是时区设置不正确造成的,本文提供了3种方法来解决这个问题. 实际上,从PHP 5. ...
- vue 挂载点 实例 模板
挂载点:vue实例 里面的el属性 对应的 id 所在的dom节点 模板:指的是挂载点内部的内容 模板可以写在挂载点内部 也可以写在属性里面 demo < ...
- java字符串简单介绍
String:String对象初始化之后不可变线程安全简单的字符串操作使用String效率更高 StringBuffer:StringBuffer对象初始化之后可改变线程安全频繁的字符串操作可以使用S ...
- Java 基础 - instanceof关键字
instanceof 父类子类 结论: 子类 instanceof 父类 == true 父类 instanceof 子类 == false public class Test { public st ...
- 关于 argc 和 argv
https://stackoverflow.com/questions/3898021/regarding-mainint-argc-char-argv 当使用命令行启动程序,或者给程序传输参数时,可 ...
- 一张图轻松掌握 Flink on YARN 应用启动全流程(上)
Flink 支持 Standalone 独立部署和 YARN.Kubernetes.Mesos 等集群部署模式,其中 YARN 集群部署模式在国内的应用越来越广泛.Flink 社区将推出 Flink ...
- thinkphp 模板继承
模板继承是一项更加灵活的模板布局方式,模板继承不同于模板布局,甚至来说,应该在模板布局的上层.模板继承其实并不难理解,就好比类的继承一样,模板也可以定义一个基础模板(或者是布局),并且其中定义相关的区 ...