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

     
  • 相关阅读:
    web fileReader API
    placeholer 改变颜色
    在选择标签中遇到的问题
    选择标签
    cesh
    sui 无限下拉分页
    调用百度地图 API 移动地图时 maker 始终在地图中间 并根据maker 经纬度 返回地址
    两种轮播图实现方式
    CSS多行文本溢出省略显示
    从Python看Web架构的发展
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10774874.html
Copyright © 2011-2022 走看看