zoukankan      html  css  js  c++  java
  • PAT 1073 Scientific Notation

    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
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    
    int to_int(string s){
        int sum=0;
        for(int i=0;i < s.size();i++){
            sum = sum*10+(s[i]-'0');
        }
        return sum;
    }
    
    
    
    int main(){
        string s;cin >> s;
        if(s[0] == '-')cout << "-";
        s = s.substr(1,s.size()-1);
    
        int pose = 0;
        for(int i=0;i < s.size();i++){
            if(s[i] == 'E')pose=i;
        }
        string s1 = s.substr(0,pose);
        string s2 = s.substr(pose+2,s.size()-pose-2);
    //    cout << s1 << " " << s2 <<endl;
    //    cout << to_int(s2);
        int cnt = to_int(s2);
    
    
        string temp="";
        for(int i=0;i<s1.size();i++){
            if(s1[i]!='.')temp = temp+s1[i];
        }
    //    cout << temp;
        if(s[pose+1] == '-'){
            string head = "0.";
            for(int i=0;i < cnt-1;i++) head = head+"0";
            head = head + temp;
            cout << head;
        }
        else if(s[pose+1] == '+'){
            if(temp.size() > cnt){
                for(int i=0;i <= cnt;i++)cout << temp[i];
                if(cnt != temp.size()-1)cout << ".";
                for(int i=cnt+1;i < temp.size();i++)cout << temp[i];
            }
            else{
                cout << temp;
                for(int i=0;i <= cnt-temp.size();i++)cout << "0";
            }
        }
    
    
    
        return 0;
    }

    _1AC

     
  • 相关阅读:
    性能计数器
    SpringBoot_数据访问-整合JPA
    SpringBoot_数据访问-整合MyBatis(二)-注解版MyBatis
    SpringBoot_数据访问-整合Druid&配置数据源监控
    SpringBoot_数据访问-JDBC&自动配置原理
    八字克妻口诀
    没想到,我能这么细心地看算法
    辰戌丑未,四库
    The jar of divisors
    分布式系统阅读笔记(十六)-----事务和并发控制
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10774874.html
Copyright © 2011-2022 走看看