PAT1073. Scientific Notation (20)
#include <iostream>
using namespace std;
string a;
int expo;
int dotPos;
int expoPos;
int i;
int main(){
cin>>a;
if(a[0]=='+'||a[0]=='-'){
if(a[0]=='-'){cout<<"-";}
a.erase(a.begin());
}
for(i=0;i<a.size();i++){
if(a[i]=='.'){
dotPos=i;
}
if(a[i]=='E'){
expoPos=i;
break;
}
}
string expoStr=a.substr(expoPos+1);
expo=stoi(expoStr);
string b=a.substr(0,expoPos);
b.erase(b.begin()+dotPos);
if(expo>0){
if((expoPos-dotPos)<=(expo+1)){
cout<<b;
int count=expo-(expoPos-dotPos)+1;
while(count--){cout<<"0";}
}else{
int i=0;
i+=expo+1;
b.insert(i,".");
cout<<b<<endl;
}
}else if(expo<0){
expo++;
cout<<"0.";
while(expo!=0){
cout<<"0";
expo++;
}
cout<<b<<endl;
}else{
cout<<a.substr(0,expoPos);
} return 0;
}
PAT1073. Scientific Notation (20)的更多相关文章
- 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 ...
- 【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 ...
随机推荐
- 云计算和SDN中的开源交换机介绍以及使用
之前关于SDN的开发工作都是在控制器层面上(以ryu为主),现在开始了新的工程项目,需要同时修改控制器和交换机的源码,如果后续项目需要,还可能需要加中间层——网络虚拟层,这部分的知识已经在前面读过了相 ...
- oracle 网络访问配置tnsnames.ora文件的路径
转自:https://blog.csdn.net/jaray/article/details/22379811 oracle 网络访问配置tnsnames.ora文件的路径 oracle 9i 是: ...
- oracle批量update
我个人觉得写的很好 http://blog.csdn.net/wanglilin/article/details/7200201 需求: 将t2(t_statbuf)表中id和t1(T_Mt)表相同的 ...
- 常用的mysql语句
为了方便学习mysql,把接触到的sql收集一下,忘记的时候可以查询一下. 连接mysql数据库: mysql -u 用户名 -p 输入密码. 创建数据库: create database 数据库名; ...
- Oracle数据库模型(OLAP/OLTP)
数据库模型 选择数据库模型: 联机事务处理OLTP(on-line transaction processing) OLTP是传统的关系数据库的主要应用,基本的.日常的事务处理.例如银行交易. OLT ...
- 对opencv.hpp头文件的认识
OpenCV学习笔记(二):对opencv.hpp头文件的认识 - 安东的技术博客 - CSDN博客 https://blog.csdn.net/xidiancoder/article/details ...
- TempData、ViewData和ViewBag异同
Data ViewData ViewBag都可以用来保存数据. 它们之间的区别如下: TempData:保存在Session中,Controller每次执行请求的时候,会从Session中先获取Tem ...
- Python(数据库之约束表的关系)
一.约束 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性 主要分为: RIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...
- 基于UDP的套接字、粘包问题
一.基于UDP的套接字 UDP服务端 ss = socket() #创建一个服务器的套接字 ss.bind() #绑定服务器套接字 inf_loop: #服务器无限循环 cs = ss.recvfro ...
- 采购订单打印并预览PDF
*&---------------------------------------------------------------------* *& Report Z01MMF019 ...