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 位,该数字及其指 ...
随机推荐
- element-ui表格合计不显示&被遮挡问题
step1:修改全局样式 .el-table{ overflow:visible !important; } .el-card__body { padding: 20px 20px 50px 20px ...
- Visual Studio 2010 启动调试报错 “访问OLE注册表的错误”
错误:访问OLE注册表的错误(异常来自HRESULT:0x8002801C(TYPE_E_REGISTRYACCESS)) 很简单,其实只要 “以管理员身份运行” Visual Studio即可.
- centos7.3更换ssh默认登陆端口
说明:本方法目前通用于7.1-7.3 vim /etc/ssh/sshd_config 找到Port 22下面添加一行:Port 12345保存退出. systemctl restart sshd.s ...
- ASP.NET MVC easyUI-datagrid 的当前页合计and总合计
一.HTML代码 <table id="dg" class="easyui-datagrid" style="width: 100%; heig ...
- .net 接受请求过来的流
//接收POST过来的数据 System.IO.Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024 ...
- offset系列属性
offset系列:获取元素的相关的样式属性的值 offsetwidth:获取元素的宽 offsetheight:获取元素的高 offsetleft:获取元素距离左边位置的值 offsettop;获取元 ...
- css----less预处理器
###less less是一种动态样式语言,属于css预处理器的范畴,它扩展了 CSS 语言, 增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展 LESS 既可以在 客户端 上运行 ,也 ...
- 在egg.js中使用mongodb
1.egg.js官网只推荐了mysqle,要用mongodb得另找资料.通过查找,大家都在用Mongoose连接,于是乎学习. 网站链接:https://www.npmjs.com/package/e ...
- 阿里云代码管理平台 Teambition Codeup(行云)亮相,为企业代码安全护航
2019杭州云栖大会企业协作与研发效能专场,企业协同平台Teambition负责人齐俊元正式发布阿里云自研的代码管理平台Teambition Codeup(行云),Codeup是一款企业级代码管理产品 ...
- 盒子阴影 box-shadow
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...