题意:

给出科学计数法的形式,转化成常规的表示,要求保留所有的有效位数

思路:纯粹的字符串处理问题,注意边界条件即可。如+1.23E+02这种,转化后是123,既不需要补0,也不需要添加小数点。

代码:

#include <iostream>
#include <string>
using namespace std;

string change(string str)
{
    string ans,sign;
    ]=='-') sign="-";
    str.erase(str.begin());

    int pos=str.find("E");
    ,str.size()--pos);
    str=str.substr(,pos);
    int exp=stoi(strExp);

    pos=str.find(".");
    str.erase(pos,);

    ){//前面添0
        ans=,')+str;
    }else{//后面补0
        ;//小数点后面的位数
        ');
        else if(len>exp) {
            ans=str;
            ans.insert(exp+,".");
        }else{
            ans=str;
        }
    }
    return sign+ans;
}

int main()
{
    string str;
    cin>>str;
    cout<<change(str);
    ;
}

1073 Scientific Notation的更多相关文章

  1. PAT 1073 Scientific Notation

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  2. 1073 Scientific Notation (20 分)

    1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...

  3. PAT 1073 Scientific Notation[字符串处理][科学记数法]

    1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...

  4. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  5. 1073. Scientific Notation (20)

    题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...

  6. PAT Advanced 1073 Scientific Notation (20 分)

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

  7. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  8. PAT甲级——1073 Scientific Notation (20分)

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

  9. PAT (Advanced Level) 1073. Scientific Notation (20)

    简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  10. PAT甲题题解-1073. Scientific Notation (20)-字符串处理

    题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...

随机推荐

  1. Google推荐——Glide使用详解(图片加载框架)

    零.前言 本文所使用的Glide版本为3.7.0 一.简介 Glide,一个被google所推荐的图片加载库,作者是bumptech.这个库被广泛运用在google的开源项目中,包括2014年的goo ...

  2. 文件IO大纲

    文件流与文件描述符的区别 a) 任何进程在运行时都默认打开3个流对象,(stdin, stdout, stderr)它们都有对应的文件描述符,其文件描述符分别为0,1,2,以后打开的文件描述符的值一般 ...

  3. netty同时支持socket和http

    项目需要使用netty做中转服务器,同时支持两种不同协议的客户端,经过几天查询资料终于找到合适的方案了,同时感谢Netty权威指南及论坛问答,开始贴代码 客户端1==>socket public ...

  4. NLP(二)_汉语言分词技术-最大匹配法

    前述 词是自然语言中最小的有意义的构成单位.汉语文本是基于单字的文本,汉语的书面表达方式以汉字作为最小单元,词与词之间没有明显的界限标志,因此,分词是汉语文本分析处理中首先要解决的问题之一. 分词可能 ...

  5. Stylus的基础用法

    介绍 在学习一个 Vue.js 项目的过程中,注意到源码中样式的部分并没有用熟悉的 .css 样式文件,而是发现了代码长得和 CSS 相像的 .styl 文件.这个 .styl 以前没见过啊,你是谁? ...

  6. 【scala】集和映射

    Scala同时提供了集(Set)和映射(Map)的可变和不可变的不同选择,但使用同样的简单名字,可以通过类继承的关系来区分可变和不可变版本. 如图所示,左边的为不可变集,右边的为可变集. //我们创建 ...

  7. iframe框架

    在一个页面里做一个区域引入另一个页面的方法: <a href="http://www.baidu.com" target="in">百度</a ...

  8. 面试题48:用C++设计一个不能被继承的类

    解法一:把构造函数设为私有 将构造函数定义为私有,然后通过定义公有的静态函数来创建和释放类的实例. { public: static SealedClass1* GetInstance() { ret ...

  9. 7.usr下重要目录和文件详解

    1./usr下重要目录和文件详解: /usr(存放用户安装的应用软件目录,如MySQL,Apache,这是一个非常重要的目录,类似于Windows下的Program Files目录,用户的很多应用程序 ...

  10. jQuery attr 与 prop 区别最简单分析

    比较经典的解释: 在处理html元素本身就带有的固有属性时,使用prop方法,对于html元素中,我们自己定义的dom属性时,使用attr方法. 而咱自己的理解是: attr会忠实的获取设置dom标签 ...