【PAT甲级】1073 Scientific Notation (20 分)
题意:
输入科学计数法输出它表示的数字。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
int ans2[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>s;
int n=s.size();
if(s[]=='-')
cout<<'-';
int pos=;
int cnt2=;
int ans=s[]-'';
for(int i=pos;i<n;++i){
if(s[i]=='E'){
pos=i+;
break;
}
ans2[++cnt2]=s[i]-'';
}
int flag=;
if(s[pos]=='-')
flag=;
++pos;
int num=;
for(int i=pos;i<n;++i){
num*=;
num+=s[i]-'';
}
if(flag){
cout<<<<'.';
for(int i=;i<num;++i)
cout<<;
cout<<ans;
for(int i=;i<=cnt2;++i)
cout<<ans2[i];
}
else{
int num2=;
cout<<ans;
int tamp=;
for(tamp=;tamp<=cnt2&&num2<num;++tamp,++num2)
cout<<ans2[tamp];
if(tamp>cnt2)
for(int i=;i<=num-num2;++i)
cout<<;
else{
cout<<'.';
for(int i=tamp;i<=cnt2;++i)
cout<<ans2[i];
}
}
return ;
}
【PAT甲级】1073 Scientific Notation (20 分)的更多相关文章
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- 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 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
随机推荐
- networkx graph save and load
Generate and parse JSON serializable data for NetworkX graphs. node_link_data(G[, attrs]) Returns da ...
- Git的安装与使用详解
git安装 下载安装git:采用默认配置安装即可 使用git --version确认是否安装成功,如下 GitHub使用: 配置sshkey,后续可以免密登录github cd / ssh-keyge ...
- SSH后台分页
初学SSH,开始用的Struts2+Hibernate3+Spring3,Hibernate中用的HibernateTemplate进行数据库的操作.之后在进行前台页面显示的时候,要用到分页,查了一下 ...
- C++分割string字符串(转)
原文链接:https://blog.csdn.net/jirryzhang/article/details/80473032 或:https://www.cnblogs.com/dingxiaoqia ...
- Dapper简介
Dapper文档 一,介绍:Dapper是一款轻量级ORM工具.如果你在小的项目中,使用Entity Framework.NHibernate 来处理大数据访问及关系映射,未免有点杀鸡用牛刀.你又觉得 ...
- js基础心得
最近有想法研究jQuery源码,一顿查阅顿感自己基础薄弱.手中正好有一本js高程,遂决定深入js基础,并记录心得至博客园.以待一举攻克jQuery,VUE等源码. 1,变量.作用域和内存问题 2,引用 ...
- python 批量编译 批量删除
把项目的py文件变异成pyc文件,好处是可以保护源码不泄露. 假如一个工程文件夹有1000个py文件,这个时候怎样快速处理 ? 两步走: ① py--->pyc python -m compi ...
- lua 随机数 math.random()和math.randomseed()用法
用法一: 不给范围,就随机算一个0~1之间的小数: 用法二:给一个参数,就取1~n之间的随机数 用法三:给两个参数,就取m~n之间的随机数 math.randomseed()用法: 由于C中 ...
- 229. 求众数 II
Q: 给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素. 说明: 要求算法的时间复杂度为 O(n),空间复杂度为 O(1). 示例 1: 输入: [3,2,3] 输出: [3 ...
- 【学习笔记】《Java编程思想》 第8~11章
第八章 多态 多态的条件: 1. 要有继承 2.父类对象引用子类对象 3. 要有方法的重写 多态的作用:消除类型之间的耦合关系. 将一个方法调用与一个方法主体关联起来称作绑定.若在程序执行前进行绑定, ...