PAT - A1073
1073 Scientific Notation (20point(s))
小数点移动的边界条件
- 小数点左移
- 超过数据左边界
- 小数点右移
- 未超过数据右边界
- 超过数据右边界
- +0.1E+2 --> 10 当科学计数法首位为0时,输出略过0
- 小数点左移
源码
#include<bits/stdc++.h>
using namespace std;
bool nsign = true; // T -> + F -> -
int pos; // 小数点位置
char A[10000]; // 初值为0
char In[10000]; // 输入字符串
int getexp(char S[]);
int main(void) {
int index = 0; // 输入字符串索引
int index_A = 0; // 生成字符串索引
scanf("%s", In);
if (In[0] == '-') nsign = false;
for (index = 1; In[index] != 'E'; ++index) {
if (In[index] != '.') {
A[index_A++] = In[index];
}
else pos = index_A; // 一般来说等于 2
}
// 退出循环时 In[index] == 'E'
pos = pos + getexp(In + index + 1); // 得到指数数值,确定小数点位置
if (In[0] == '-') printf("-");
if (pos <= 0) {
for (int i = pos - 1; i < index_A; ++i) {
if (i < 0) {
printf("0");
if (i == pos - 1) printf(".");
}
else printf("%c", A[i]);
}
} else if (pos > 0 && pos < index_A) {
for (int i = 0; i < index_A; ++i) {
if (i == pos) printf(".");
printf("%c", A[i]);
}
} else if (pos >= index_A) {
for (int i = 0; i < pos; ++i) {
if (i < index_A) printf("%c", A[i]);
else printf("0");
}
}
printf("\n");
return 0;
}
int getexp(char S[]) {
int exp = 0;
for (int i = 1; i < strlen(S); ++i)
exp = exp * 10 + S[i] - '0';
if (S[0] == '-') exp = -exp;
return exp;
}
PAT - A1073的更多相关文章
- PAT A1073 Scientific Notation (20 分)——字符串转数字
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT题目AC汇总(待补全)
题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...
- PAT_A1073#Scientific Notation
Source: PAT A1073 Scientific Notation (20 分) Description: Scientific notation is the way that scient ...
- PAT B1024/A1073 科学计数法
书中AC代码 #include <cstdio> #include <cstring> #include <iostream> #include <cmath ...
- PAT甲级——A1073 Scientific Notation
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT/字符串处理习题集(二)
B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...
- 《转载》PAT 习题
博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...
- PAT Judge
原题连接:https://pta.patest.cn/pta/test/16/exam/4/question/677 题目如下: The ranklist of PAT is generated fr ...
- PAT 1041. 考试座位号(15)
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...
随机推荐
- javascirpt获取随机数
/* getran(min, max, n): 获取min与max之间的随机数 n: n保留浮点数数量 */ function getran(min, max, n){ return Number(( ...
- MSSqlServer访问远程数据库
--第一部分(要点)--永久访问方式(需对访问远程数据库进行经常性操作)时设置链接数据库Exec sp_addlinkedserver 'MyLinkServer','','SQLOLEDB','远程 ...
- Keras深度学习框架之损失函数
一.损失函数的使用 损失函数[也称目标函数或优化评分函数]是编译模型时所需的两个参数之一. model.compile(loss='mean_squared_error', optimizer='sg ...
- 分享下超实用的用skura frp做内网穿透的经验
操作目的: 使无公网ip的主机能被外网访问,实现ssh对服务器的远程管理 硬件准备: 1.服务端:skura frp主机(skura frp 免费提供,有待创建) 2.客户端:接在无线路由器(内网)上 ...
- axios,vue-echarts, async, vue 图表数据处理; axios 跨域代理; 异步同步请求接口;生命周期函数
1.vue-echarts 安装和组件引用 插件官网 https://github.com/ecomfe/vue-echarts 安装 npm install eacharts vue-echarts ...
- #《Essential C++》读书笔记# 第五章 面向对象编程风格
基础知识 继承机制定义了父子(parent/child)关系.父类(parent)定义了所有子类(children)共通的共有接口(public interface)和私有实现(private imp ...
- css的三种导入方式
内联样式表 <p style="font-size:50px; color:blue">css内联样式表</p> 内部样式表 <style type= ...
- Umi 小白纪实(三)—— 震惊!路由竟然如此强大!
在<Umi 小白纪实(一)>中有提到过简单的路由配置和使用,但这只是冰山一角 借用一句广告词,Umi 路由的能量,超乎你的想象 一.基本用法 Umi 的路由根结点是全局 layout s ...
- 快速读写模板(int)
一.快速读入模板(int) inline int read(int x){ char ch=getchar(); int x=0,f=1; while(ch>='9'||ch<='0'){ ...
- Linux物理磁盘扩容流程
1. 插入硬盘前,查看现有硬盘情况 (1)命令:fdisk -l 说明:fdisk -l 查看设备的所有分区 (2)命令:df -h 说明:df 列出文件系统的整体磁盘使用量 2. 断电插入硬盘后,重 ...