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 ...
随机推荐
- [转]python-元类
转载于:刘羽冲 两句话掌握python最难知识点——元类 千万不要被所谓“元类是99%的python程序员不会用到的特性”这类的说辞吓住.因为每个中国人,都是天生的元类使用者 学懂元类,你只需要知道两 ...
- Editplus配置Monokai页面风格
1.找到EditPlus的配置文件editplus_u.ini,用以下代码替换 [Options] Placement=2C00000002000000030000000083FFFF0083FFFF ...
- LCS/LIS/LCIS 模板总结
/************************* LCS/LIS/LCIs模板总结: *************************/ /*************************** ...
- 12.php中无比坑爹的构造函数。
当你在php类中,写一个构造方法时,记得,一定要用__这是两个下划线,而不是一个.......... <?php class Car { // function _construct() { / ...
- Android 中 js 和 原生交互
Android中的WebView 中加载的URL 默认是在手机浏览器中加载的,我们可以覆盖这种默认的动作,让网页在WebView中打开.通过设置WebView的WebViewClent 达到这个效果. ...
- sql中in和exists的区别
in 和exists in是把外表和内表作hash 连接,而exists 是对外表作loop 循环,每次loop 循环再对内表进行查询. 一直以来认为exists 比in 效率高的说法是不准确的.如果 ...
- 面试题15:链表中倒数第K个结点
输入一个链表,输出该链表中倒数第k个结点. 方法1: 这个解法要循环两次链表 /* public class ListNode { int val; ListNode next = null; Lis ...
- Python WSGI v1.0 中文版(转)
add by zhj: WSGI全称Web Server Gateway Interface,即Web网关接口.其实它并不是OSI七层协议中的协议,它就是一个接口而已,即函数,而WSGI规定了该接口的 ...
- JavaScript整理1
JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一.如何编写 1.J ...
- 海报工厂之(一)android 如何给图片添加水印和文字
在Android中如何给图片添加水印,下面截取了部分核心代码,仅供参考: /** * 获取图片缩小的图片 * @param src * @return */ ...