zoukankan      html  css  js  c++  java
  • 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

    题解

    乙级原题
    https://blog.csdn.net/qq_41581765/article/details/119791168

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif
        string s;
        cin>>s;
        int i=0;
        while(s[i]!='E') i++;
        string num=s.substr(1,i-1);
        int exp=stoi(s.substr(i+1));
        if(s[0]=='-') cout<<"-";
        if(exp<0){
            cout<<"0.";
            for(int j=0;j<abs(exp)-1;j++) cout<<'0';
            for(int j=0;j<num.length();j++)
                if(num[j]!='.') cout<<num[j];
        }
        else{
            cout<<num[0];
            int cnt,j;
            for(j=2,cnt=0;j<num.length()&&cnt<exp;j++,cnt++)
                cout<<num[j];
            if(j==num.length()){
                for(int k=0;k<exp-cnt;k++) cout<<'0';
            }else{
                cout<<'.';
                for(int k=j;k<num.length();k++)
                    cout<<num[k];
            }
        }
        return 0;
    }
    

    本文来自博客园,作者:勇往直前的力量,转载请注明原文链接:https://www.cnblogs.com/moonlight1999/p/15605477.html

  • 相关阅读:
    HDU
    POJ
    快速幂运算
    RocketMQ集群
    RocketMQ角色介绍
    RocketMQ初探
    MySQL 串行隔离级别小记
    分布式事务笔记
    MySQL分库分表篇
    MySQL主从篇
  • 原文地址:https://www.cnblogs.com/moonlight1999/p/15605477.html
Copyright © 2011-2022 走看看