1073 Scientific Notation(20 分)

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

code

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    string num,ep;
    char ns,es;
    int e;
    cin >> s;
    e = s.find("E");
    num = s.substr(1,e-1);
    ns = s[0];
    es = s[e+1];
    ep = s.substr(e+2);
    num.erase(1,1);
    if(ns=='-') cout << ns;
    if(es=='-') {
        cout << "0.";
        for(int i=1;i<stoi(ep);i++)
        {
            cout << "0";
        }
        cout << num;
    } else {
        if(stoi(ep)>=num.length()-1) {
            cout << num;
            for(int i=0;i<stoi(ep)-num.length()+1;i++)
            {
                cout << "0";
            }
        } else {
            num.insert(stoi(ep)+1,".");
            cout << num;
        }
    }
    return 0;
}

note

  • C++ string类的用法,erase,insert,find,substr,length 都要熟练
  • stoi()to_string() 完成整数和字符串的相互转换
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,196评论 0 10
  • 沧北有兽,其名梦华,红瞳炎发,能化人形。性善,食梦,能言语,逢多灾现人间,惊之露兽角。世人异之,捕杀以售,后绝。—...
    Zh修阅读 4,143评论 1 2
  • 今天聆听了王春梅老师的《做一个自带光芒的教育人》讲座,没有洗脑的鸡汤文,处处都是干货,我喜欢。会说话有多重要?“会...
    如月_a387阅读 1,405评论 0 0
  • 听到这首歌特别有感触,原来女人对男人的期待无非是: 关怀 聆听 理解 对于情感的需求更高,但是又多人会理解,无比坚...
    不吃面条always阅读 2,844评论 0 0
  • 出发去林芝,西藏的香巴拉。只道是雪域高原,竟会有这么郁郁葱葱的河谷。感觉他们真想要独的话,这里还有点资本。可是导游...
    XinSuting阅读 1,877评论 0 0

友情链接更多精彩内容