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 ...
随机推荐
- hdu3535(AreYouBusy)
题目链接:传送门 题目大意:有 n 组任务,m 个体力,每组任务有 k 个,分类为 f,每个任务花费 x 体力,得到 y 开心值,求最大开心值,若不能完成输出-1 分类为 0:这一组中的 k 个任务至 ...
- git 分回滚后无法合并代码问题
git reset & git revert 区别: 1. git revert是用一次新的commit来回滚之前的commit,git reset是直接删除指定的commit. 2. 在回滚 ...
- 巨蟒python全栈开发数据库前端7:jQuery框架
每个人的标准不同,看法等等,认识,价值观有所不同,促成了这些矛盾. 1.select例子 <!DOCTYPE html> <html lang="en"> ...
- mysql replace 使用注意,update的时候 删除从表数据
使用REPLACE插入一条记录时,如果不重复,REPLACE就和INSERT的功能一样,如果有重复记录,REPLACE就使用新记录的值来替换原来的记录值. 使用REPLACE的最大好处就是可以将DEL ...
- python得到一个10位随机数的方法及拓展
https://blog.csdn.net/qq_33324608/article/details/78866760 无意中看到一个写10位随机数的方法,很有想法,然后就从学了一下随机数,相关东西都记 ...
- String StringBuffer StringBuilder 老生常谈
1.String 与 StringBuffer . StringBuilder的区别 String 字符串常量 而 (StringBuffer 和 StringBuilder 字符串变量) 执行速度上 ...
- C#检测两个文件内容是否相同
不知道为什么对Excel 2010 xlsx后缀的文件没有效果,求解! 对其他文件有效,如.txt,.csv using System; using System.Security.Cryptogra ...
- python 测试代码
1.使用print()打印 测试代码最简单的就是添加一些print()语句.然而产品开发中,需要记住自己添加的所有print()语句并在最后删除,很容易出现失误. 2.使用pylint.pyflake ...
- 美国评出2016最值得去的旅游胜地+纯电动车郊游记+DIY一个小电动车
美国评出2016最值得去的旅游胜地(10) http://bbs.miercn.com/bd/201510/thread_569397_1_10.html 自带发电机! 北汽E150 EV纯电动车郊游 ...
- java队列的实现
队列也可以通过数组和链表两种方式来实现. 1.链表方式实现 class Node{ Node next = null; int data; public Node(int data){this.dat ...