ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PAT Advanced 1073 Scientific Notation (20 分)

2019-11-06 15:01:19  阅读:291  来源: 互联网

标签:deque 20 Scientific Notation decimal back str Integer notation


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 <deque>

using namespace std;

int main()
{
    string str;
    cin>>str;
    char sign=str[0];
    deque<char> deque_Integer;//整数
    deque<char> deque_decimal;//小数
    int i;
    for(i=1;str[i]!='.';i++) deque_Integer.push_back(str[i]);
    for(i=i+1;str[i]!='E';i++) deque_decimal.push_back(str[i]);
    bool sign2=str[++i]=='+' ? 1:0;//获取符号,1右移,2左移
    int num=stoi(str.substr(i+1,str.length()-i-1));//左移或者右边移动的数量
    if(sign2){//右移
        while(num--){
            if(!deque_decimal.empty()){
                deque_Integer.push_back(deque_decimal.front());
                deque_decimal.pop_front();
            }else deque_Integer.push_back('0');
        }
    }else{//左移
        while(num--){
            if(!deque_Integer.empty()){
                deque_decimal.push_front(deque_Integer.back());
                deque_Integer.pop_back();
            }else deque_decimal.push_front('0');
        }
    }
    //输出
    if(sign!='+') cout<<sign;
    if(deque_Integer.size()==0) cout<<"0";
    else for(int i=0;i<deque_Integer.size();i++) cout<<deque_Integer[i];
    if(deque_decimal.size()!=0){
        cout<<".";
        for(int i=0;i<deque_decimal.size();i++) cout<<deque_decimal[i];
    }
    system("pause");
    return 0;
}

 

标签:deque,20,Scientific,Notation,decimal,back,str,Integer,notation
来源: https://www.cnblogs.com/littlepage/p/11805196.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有