zoukankan      html  css  js  c++  java
  • PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指数部分的正负号即使对正数也必定明确给出。

    现以科学计数法的格式给出实数 A,请编写程序按普通数字表示法输出 A,并保证所有有效位都被保留。

    输入格式:

    每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 A。该数字的存储长度不超过 9999 字节,且其指数的绝对值不超过 9999。

    输出格式:

    对每个测试用例,在一行中按普通数字表示法输出 A,并保证所有有效位都被保留,包括末尾的 0。

    输入样例 1:

    +1.23400E-03
    

    输出样例 1:

    0.00123400
    

    输入样例 2:

    -1.2E+10
    

    输出样例 2:

    -12000000000

    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<iostream>
    #include<stack>
    using namespace std;
    int main() {
        //数据定义和分离
        string s;
        stack<char> integer;
        stack<char> decimal;
        stack<char> res;
        int mv=0;
        cin>>s;
        char sf=s[0],sf2;//第一位符号位
        int tmp;
        for(int i=1;s[i]!='.';i++){
            integer.push(s[i]);
            tmp=i+2;
        }
        for(int i=tmp;s[i]!='E';i++){
            decimal.push(s[i]);
            tmp=i+3;
        }
        sf2=s[tmp-1];
        for(int i=tmp;i<s.length();i++){
            mv=mv*10+(s[i]-'0');
        }
        //数据处理
        while(!decimal.empty()){
            res.push(decimal.top());
            decimal.pop();
        }
        if(sf2=='+'){
            while(mv--){
                if(res.empty()) integer.push('0');
                else{
                    integer.push(res.top());
                    res.pop();
                }
            }
        }
        if(sf2=='-'){
            while(mv--){
                if(integer.empty()) res.push('0');
                else{
                    res.push(integer.top());
                    integer.pop();
                }
            }
        }
        if(!res.empty())res.push('.');
        while(!integer.empty()){
            res.push(integer.top());
            integer.pop();
        }
        if(sf=='-') cout<<sf;
        if(res.top()=='.') cout<<0;
        while(!res.empty()){
            cout<<res.top();
            res.pop();
        }
        system("pause");
        return 0;
    }
  • 相关阅读:
    排序系列 之 希尔排序算法 —— Java实现
    排序系列 之 快速排序算法 —— Java实现
    排序系列 之 冒泡排序及其改进算法 —— Java实现
    排序系列 之 折半插入排序算法 —— Java实现
    排序系列 之 直接插入排序算法 —— Java实现
    Three.js入门篇(一)创建一个场景
    THREE.JS(如何想场景中添加物体对象)
    Tween.js 动画效果
    js柯里化
    node path模块
  • 原文地址:https://www.cnblogs.com/littlepage/p/11300837.html
Copyright © 2011-2022 走看看