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 ...
随机推荐
- 【RabbitMQ】3、win7下安装RabbitMQ
RabbitMQ依赖erlang,所以先安装erlang,然后再安装RabbitMQ; erlang,下载地址:http://www.erlang.org/download RabbitMQ,下载地址 ...
- 【Spring】13、使用Spring 3的@value简化配置文件的读取
Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在applicationContext.xml文件中配置properties文件 & ...
- 简单说一下UWP中的JumpList
在Windows10的10856这个版本中,微软为桌面版提供了一组新的应用交互方式,磁贴和Toast通知的个性化都有了一定的改善.针对磁贴方面,微软为我们提供了一组新的API来扩充我们对应用的交互方式 ...
- 【工具相关】Web--nodejs的安装
一,从官网下载nodejs.org. https://nodejs.org/en/ 二,按照步骤一步一步安装就好.
- SAP MM PIR里的Lower Limit & Upper Limit
SAP MM PIR里的Lower Limit & Upper Limit 在PIR的价格的detail数据里,有2个字段:Lower Limit和Upper Limit.在今天之前,笔者从未 ...
- 卷积神经网络CNNs的理解与体会
https://blog.csdn.net/shijing_0214/article/details/53143393 孔子说过,温故而知新,时隔俩月再重看CNNs,当时不太了解的地方,又有了新的理解 ...
- 无法给MySQL root用户修改密码的解决方法
本人编译安装完MySQL数据库,想给root用户修改密码,结果无法修改,并且报错,报错大概信息如下: mysqladmin: connect to server at 'localhost' fail ...
- 测试思想-流程规范 SVN代码管理与版本控制
SVN代码管理与版本控制 by:授客 QQ:1033553122 欢迎加入软件性能测试交流群(QQ群):7156436 目录 一. 二. 三. 四. 五. 六. 七. 一. 创建根目录 创建一 ...
- OneAPM大讲堂 | 谁更快?JavaScript 框架性能评测
文章系国内领先的 ITOM 管理平台供应商 OneAPM 编译呈现. 网页性能是一个丰富且又复杂的话题.在本帖中,我们会将讨论的范围局限在前端 JavaScript 框架上,探究相对于另外一种框架而言 ...
- python第六十八天--第十二周作业
主题: 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上课纪录对应多条 ...