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考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...
随机推荐
- java程序设计原则知多少
程序设计七大原则 一.开闭原则 针对我们设计的功能模块对扩展开放,对修改关闭:利用面向接口(抽象)编程(多态的特性),实现对功能需求扩展的同时,不允许更改原来的代码.提高对象的可复用性.可维护性. ...
- ELF文件之九——使用链接脚本-2个函数-data-bss-temp-call-debug信息-struct
main.c int enable; ; struct aaa { int membera; char memberb; }s_aaa; int main() { int temp; add(); d ...
- 终于解决 k8s 集群中部署 nodelocaldns 的问题
自从开始在 kubernetes 集群中部署 nodelocaldns 以提高 dns 解析性能以来,一直被一个问题困扰,只要一部署 nodelocaldns ,在 coredns 中添加的 rewr ...
- rabbit MQ 消息队列
为什么会需要消息队列(MQ)? 一.消息队列概述消息队列中间件是分布式系统中重要的组件,主要解决应用解耦,异步消息,流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构.目前使用较多的消息队列有 ...
- 一键安装MySQL5.6.43脚本
[root@lamp ~]# cat /server/scripts/mysql-5.6.43_install.sh #!/bin/bash #卸载系统自带的Mysql /bin/rpm -e $(/ ...
- log4j2 springboot 特点与使用方法
Apache Log4j2 is an upgrade to Log4j that provides significant improvements over its predecessor, Lo ...
- Ajax0002: 省市县三级联动案例
- 【01】HTML_day01_03-HTML常用标签
typora-copy-images-to: media 第01阶段.前端基础.HTML常用标签 学习目标 理解: 相对路径三种形式 应用 排版标签 文本格式化标签 图像标签 链接 相对路径,绝对路径 ...
- Openshift中Pod的SpringBoot2健康检查
Openshift中Pod的SpringBoot2应用程序健康检查 1. 准备测试的SpringBoot工程, 需要Java 8 JDK or greater and Maven 3.3.x or g ...
- 高并发系统:消息队列MQ
注:前提是知道什么是消息队列.不懂的去搜索各种消息队列入门(activeMQ.rabbitMQ.rocketMQ.kafka) 1.为什么要使用MQ?(MQ的好处:解耦.异步.削峰) (1)解耦:主要 ...