1073 Scientific Notation
题意:
给出科学计数法的形式,转化成常规的表示,要求保留所有的有效位数
思路:纯粹的字符串处理问题,注意边界条件即可。如+1.23E+02这种,转化后是123,既不需要补0,也不需要添加小数点。
代码:
#include <iostream>
#include <string>
using namespace std;
string change(string str)
{
string ans,sign;
]=='-') sign="-";
str.erase(str.begin());
int pos=str.find("E");
,str.size()--pos);
str=str.substr(,pos);
int exp=stoi(strExp);
pos=str.find(".");
str.erase(pos,);
){//前面添0
ans=,')+str;
}else{//后面补0
;//小数点后面的位数
');
else if(len>exp) {
ans=str;
ans.insert(exp+,".");
}else{
ans=str;
}
}
return sign+ans;
}
int main()
{
string str;
cin>>str;
cout<<change(str);
;
}
1073 Scientific Notation的更多相关文章
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- 1073 Scientific Notation (20 分)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- 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 (Advanced Level) 1073. Scientific Notation (20)
简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT甲题题解-1073. Scientific Notation (20)-字符串处理
题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...
随机推荐
- scala学习手记7 - 运算符重载
从语法上来说scala是没有运算符的.之前的一节里也曾提到过scala的运算符实际上是方法名,如1 + 2实际上就是1.+(2).我们可以将之视为运算符,是因为scala的一个特性:如果方法的参数小于 ...
- JNIjw05
ZC: 这个代码,没有真正的运行测试 1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw05.h" #in ...
- 卸载oracle11g
完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraHome ...
- 将本地代码提交到gitlub
第一步:建立git仓库 cd到本地项目根路径下面,执行git命令:git init $ git init Initialized empty Git repository in D:/my_wor ...
- hibernate12--注解
在之前的基础上删除hbm.xml映射文件 之后修改实体类内容 /** * 部门的实体类 * strategy对应的就是主键生成策略 * GenerationType: * 01.auto:自动选择合适 ...
- Agilent RF fundamentals (1)- fundamental units of measure
- 【CSAPP】三、程序的机器级表示
本章基于两种相关的机器语言:Intel IA32和x86-64,前者注重32位,后者注重64位. 本章脉络:c\汇编\机器码之间的关系,数据的表示,控制结构如何实现.运行栈,局部变量的存储,数据结构. ...
- iOS在支持arc的工程中,导入不支持arc的第三方的插件
首先将插件导入到工程中,然后点击工程名,在targets下面找到相应的条目,然后选择build phares,打开第二行compile sourses,然后找到不支持arc的.m文件,在后边添加上“- ...
- Ruby on Rails入门——macOS 下搭建Ruby Rails Web开发环境
这里只介绍具体的过程及遇到的问题和解决方案,有关概念性的知识请参考另一篇:Ruby Rails入门--windows下搭建Ruby Rails Web开发环境 macOS (我的版本是:10.12.3 ...
- python中的赋值与拷贝(浅拷贝与深拷贝)
1.赋值与拷贝 直接赋值(b=a)是传引用,b改动a也会改动. a = [1, 2, 3, 4] b = a b[1] = 999 print(a, b) #[1, 999, 3, 4] [1, 99 ...