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

     
  • 相关阅读:
    del:根据索引值删除元素
    Python insert()方法插入元素
    Python extend()方法添加元素
    Python append()方法添加元素
    Python list列表添加元素的3种方法
    什么是序列,Python序列详解(包括序列类型和常用操作)
    Python运算符优先级和结合性一览表
    Python print()函数高级用法
    Python input()函数:获取用户输入的字符串
    Python变量的定义和使用
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10774874.html
Copyright © 2011-2022 走看看