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并发工具类】Java并发容器
前言 Java并发包有很大一部分都是关于并发容器的.Java在5.0版本之前线程安全的容器称之为同步容器.同步容器实现线程安全的方式:是将每个公有方法都使用synchronized修饰,保证每次只有一 ...
- 【转载】signal(SIGCHLD, SIG_IGN)和signal(SIGPIPE, SIG_IGN)
来源:https://blog.csdn.net/guotao1983/article/details/82118218 signal(SIGCHLD, SIG_IGN) 因为并发服务器常常fork很 ...
- 响应式Web设计:构建令人赞叹的Web应用程序的秘诀
骨架屏(Skeleton Screen) 参考博客:https://medium.com/@owencm/reactive-web-design-the-secret-to-building-web- ...
- vue插件介绍
1.插件和组件的关系 在没有封装组件之前,如果不使用第三方插件,那么很多情况下我们会编写几个常用的组件来提供给页面使用,如Alert/Loading组件,而你可能需要在很多页面中引入并且通过compo ...
- emmet笔记
1.div.div${div$}*6 生成 <div class="div1">div1</div> <div class="div2&qu ...
- 第三篇 SpringBoot整合log4j2详解
源代码:https://pan.baidu.com/s/1d1Lwv1gIvVNltIKVWeEseA 提取码:wff0 SpringBoot整合Log4j2步骤: 1.删除spring-boot-s ...
- Arm开发板+Qt学习之路-multiple definition of
问题描述:在一个头文件a.h中定义一些变量x,在其他.c文件中(b.c,c.c)要用到.用一般的全局变量的方法,编译时总是提示error:multiple definition of x 问题分析:o ...
- Linux下使用Nginx
模拟tomcat集群 1.下载tomcat7,/usr/local下新建目录tomcat,将tomcat7剪切到/usr/local/tomcat wget http://mirror.bit.edu ...
- 利用Bellman-Ford算法(有向图) 判断负环
// 根据Bellman-Ford算法的原理 // 判断负环(算法的最大更新次数,应该是顶点数-1次) // 而如果存在负环,算法会一直更新下去 // 我们根据循环进行的次数,来判断负环 #inclu ...
- 刷题84. Largest Rectangle in Histogram
一.题目说明 题目84. Largest Rectangle in Histogram,给定n个非负整数(每个柱子宽度为1)形成柱状图,求该图的最大面积.题目难度是Hard! 二.我的解答 这是一个 ...