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的更多相关文章

  1. PAT A1073 Scientific Notation (20 分)——字符串转数字

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  2. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  3. PAT_A1073#Scientific Notation

    Source: PAT A1073 Scientific Notation (20 分) Description: Scientific notation is the way that scient ...

  4. PAT B1024/A1073 科学计数法

    书中AC代码 #include <cstdio> #include <cstring> #include <iostream> #include <cmath ...

  5. PAT甲级——A1073 Scientific Notation

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  6. PAT/字符串处理习题集(二)

    B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...

  7. 《转载》PAT 习题

    博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...

  8. PAT Judge

    原题连接:https://pta.patest.cn/pta/test/16/exam/4/question/677 题目如下: The ranklist of PAT is generated fr ...

  9. PAT 1041. 考试座位号(15)

    每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...

随机推荐

  1. vue 信使 ------fetch、axios

    fetch 1.什么是fetch 相当于promise 必须写两个then 第一个then返回状态码 返回成json格式 第二个then返回json数据 2.使用方法 $ npm install fe ...

  2. Python - os.walk()详细使用

    os.walk() 方法简单介绍 主要用来遍历一个目录内各个子目录和子文件 是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 方法参数介绍 os.walk(top[, t ...

  3. oracle-11g-R2监听文件配置

    客户端连接oracle数据库时出现如下错误: Listener refused the connection with the following error: ORA-, TNS:listener ...

  4. PWA 推送实践

    PWA 推送实践 最近公司内录任务的系统总是忘记录任务,而那个系统又没有通知,所以想要实现一个浏览器的通知功能,免得自己忘记录入任务. 前端实现通知的几种方式 想要实现通知,我们就需要有个客户端,对于 ...

  5. [PHP] 使用PHP在mongodb中进行count查询

    在php7的mongodb扩展中,当要查询某个集合在某个条件下的数据个数时,可以使用下面的方式来获取. 比原生的命令要复杂许多 比旧版mongo扩展也复杂许多 需要使用到MongoDB\Driver\ ...

  6. postgresql 文件布局

    我们知道linux中一个思想:一切皆文件,那么在我们安装完postgresql数据库后,她长什么样呢?本文带着你一起揭开她的面纱,看看postgresql的文件布局. 说明:由于安装测试的版本是10. ...

  7. STT-MRAM存在的两个弊端

    随着自旋转移矩效应的发现以及材料和结构的优化,基于自旋转移矩效应的STT-MRAM器件应运而生.自从自旋转移矩效应被证实以来,一方面研究人员通过大量的努力尝试降低磁化反转的临界电流,增加热稳定性:另一 ...

  8. Eclipse部署项目,常见几个问题解决方案

    一.java compiler level does not match the version of the inst 解决方案:(一般出现在拷贝项目) 第一步:在Eclipse环境中,鼠标右键选择 ...

  9. [更新ing]zzy的家里蹲网课日记

    前言 精神小(ge)伙(zi)终于记起了他的博客密码...... 寒假以来,积累了巨多的好想法想要写博客,往往都是因为各种原因半途而废--在学习生活上甚至也有各种拖延的毛病:爱欠作业不早睡,不见成绩不 ...

  10. PHP0015:PHP分页案例