PAT A1073 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
#include <stdio.h>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
using namespace std; int main(){
string a;
cin >> a;
if (a[] == '-'){
printf("-");
a.erase(, );
}
else if (a[] == '+'){
a.erase(, );
}
a.erase(, );
int pos_e;
pos_e = a.find('E');
string sub_str = a.substr(pos_e + , a.length() - pos_e - );
int flag = ;
if (sub_str[] == '-')flag = -;
a.erase(pos_e, + sub_str.length());
sub_str.erase(, );
while (!sub_str.empty() && sub_str[] == ''){
sub_str.erase(, );
}
int exp = ;
if (sub_str.empty())exp = ;
else{
for (int i = ; i < sub_str.length(); i++){
exp = exp * + sub_str[i] - '';
}
}
int extra = ;
if (flag == -){
for (int i = ; i < exp - ; i++){
a.insert(, "");
}
a.insert(,"0.");
}
else{
int l = a.length(); if (exp >= l - ){
for (int i = ; i < exp - l+;i++){
a.insert(a.length(),"");
} }
else{
a.insert( + exp, ".");
}
}
cout << a;
system("pause");
}
注意点:和B1024一样,就是分情况实现,字符串转数字,要记得字符串的find,erase,substr操作。
PAT A1073 Scientific Notation (20 分)——字符串转数字的更多相关文章
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- 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分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- 【PAT甲级】1073 Scientific Notation (20 分)
题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT甲级——A1073 Scientific Notation
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
随机推荐
- webpack4 系列教程(十): 图片处理汇总
多图预警!!! 此篇博文共 5 张图(托管在 GitHub),国内用户请移步>>>原文. 或者来我的小站哦 0. 课程源码和资料 本次课程的代码目录(如下图所示): >> ...
- hive的本地安装部署,元数据存储到mysql中
要想使用Hive先要有hadoop集群的支持,使用本地把元数据存储在mysql中. mysql要可以远程连接: 可以设置user表,把localhost改为%,所有可连接.记住删除root其他用户,不 ...
- 判断api请求方式
$curl_request = $_SERVER['REQUEST_METHOD']; //获取请求方式 if($curl_request == 'POST'){ echo post; }else i ...
- Oracle总结二
1 where子句 Where子句的作用:用where子句来指定查询条件 1.1 用法示例 select * from emp where deptno=10; select * from emp w ...
- JS中的数学方法
1 . Math.ceil() 向上取整 2. Math.floor() 向下取整 3. Math.round() 四舍五入取整 4. Math.random() 生成 ...
- 移动端安卓手机不能识别border 0.5px解决方案
由于安卓手机无法识别border 0.5px,因此我们要用0.5px的话必须要借助css3中的-webkit-transform:scale缩放来实现, 原理:将伪元素的宽设为200%,height设 ...
- Web API的参数、多版本和Filter
一.关于API的参数a) Web API在WebApiConfig.cs中配置了路由模板,默认为"api/{controller}/{id}",这与MVC路由模板的区别在于没有{a ...
- js 监听事件的叠加和移除
html DOM元素有很多on开头的监听事件,如onload.onclick等,见DOM事件列表.但是同一种事件,后面注册的会覆盖前面的: window.onresize = function(){ ...
- [Hadoop] Windows 下的 Hadoop 2.7.5 环境搭建
原文地址:https://www.cnblogs.com/memento/p/9148721.html 准备说明: jdk:jdk-8u161-windows-x64.exe hadoop:hadoo ...
- EaseType 缓动函数
EaseType(动画曲线) EaseType 缓动函数或者我习惯叫它动画曲线,在很多的软件或动画中都有涉及到,下面是摘取的一些资料: 缓函数图例 Tween效果 每一幅图像当鼠标移上去,会有路径效果 ...