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 ...
随机推荐
- 【转载&总结】后缀数组及广泛应用
转自:http://blog.csdn.net/yxuanwkeith/article/details/50636898 五分钟搞懂后缀数组!后缀数组解析以及应用(附详解代码) 作者:YxuanwKe ...
- 【BZOJ4688】One-Dimensional 矩阵乘法
[BZOJ4688]One-Dimensional Description 考虑一个含有 N 个细胞的一维细胞自动机.细胞从 0 到 N-1 标号.每个细胞有一个被表示成一个小于 M 的非负整数的状态 ...
- java.lang.IllegalArgumentException: Failed to decrypt.
加密失败. 附加信息: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Co ...
- swift UITextField
var textField = UITextField(frame: CGRectMake(10,160,200,30)) //设置边框样式为圆角矩形 textField.borderStyle = ...
- gitlab 阿里邮箱配置
gitlab 阿里邮箱配置 # gitlab_rails['smtp_user_name'] = "smtp user"# gitlab_rails['smtp_password' ...
- lombok插件使用
1.1 lombok介绍 lombok 是一个可以帮助我们简化java代码编写的工具类,尤其是简化javabean的编写,可以通过采用注解的方式,消除代码中的构造方法,getter/setter等代码 ...
- 东方通tongweb linux安装
1.把安装的bin文件和license.dat文件放到/opt目录下 2.运行$sh Install_TW5.0.0.0_Standard_Linux.bin -i console 命令在 Linux ...
- Sum---poj1844(数学题)
题目链接:http://poj.org/problem?id=1844 题意:给一个整数n,求当n由1到k的连续整数加或减组成时的最小的k. 如果n全部由加法组成,那么k可以组成k(k+1)/2,设减 ...
- django--个人主页建立练习
1.前端页面采用模板继承与动态模板 {% extends 'base.html' %} {% block content %} {% for article in article_list %} &l ...
- python进程锁
import time import threading import multiprocessing lock = multiprocessing.RLock() def task(arg): pr ...