题意:

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

思路:纯粹的字符串处理问题,注意边界条件即可。如+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. NFS的安装配置使用

    /////////////////////////////NFS///////////////////////////////////////////////////写在前面:NFS在数据传输/信息传 ...

  2. pandas 选取数据 修改数据 loc iloc []

    pandas选取数据可以通过 loc iloc  [] 来选取 使用loc选取某几列: user_fans_df = sample_data.loc[:,['uid','fans_count']] 使 ...

  3. Android TextView 设置滚动条(纯xml)

    <ScrollView android:id="@+is/scrollView_id" android:layout_width="fill_parent" ...

  4. linux rpm命令安装卸载 初步使用

    安装(以安装jdk为例) 1.下载后,首先把jdk-7u3-linux-x64.rpm复制到/usr/local/src#cp jdk-7u3-linux-x64.rpm /usr/local/src ...

  5. LeetCode OJ:Binary Tree Postorder Traversal(后序遍历二叉树)

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...

  6. Qt 出现“undefined reference to `vtable for”原因总结

    http://blog.csdn.net/chenlong12580/article/details/7431104

  7. Kotlin 第一弹:自定义 ViewGroup 实现流式标签控件

    古人学问无遗力, 少壮工夫老始成.纸上得来终觉浅, 绝知此事要躬行. – 陆游 <冬夜读书示子聿> 上周 Google I/O 大会的召开,宣布了 Kotlin 语言正式成为了官方开发语言 ...

  8. ip分包研究-以UDP为例

    原文 http://www.jianshu.com/p/741cb12ab0c9 测试环境: 利用iOS的NE从TUN抓取IP packets,如下代码分析ip包: uint16_t iphid = ...

  9. Linux下windows中文文本文件乱码问题

    table of content: 乱码问题 用gedit选择正确的字符编码打开文件 文件转码 总结 §乱码 Fedora安装时默认用UTF-8字符编码方式, 这么做有国际化的好处(和很多用utf-8 ...

  10. Django cookie与session

    cookie与session关系 cookie 是保存在客户端浏览器的键值对,浏览器发送请求时候会自动携带. session 1.生成随机字符串 2.回给浏览器,让它写到cookie # {" ...