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 <string>
#include <cstring>
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s[0] == '-')
        cout << "-";
    int n,i;
    for(i = 1; s[i] != 'E'; i++);
    string t = s.substr(1,i-1);
    n = stoi(s.substr(i+1));
    if(n < 0)
    {
        cout << "0.";
        for(int j = 0; j < abs(n)-1; j++)
            cout << "0";
        for(int j = 0; j < t.length(); j++)
        {
            if(t[j] != '.')
                cout << t[j];
        }
    }
    else{
        if(n >= t.length()-2)
        {
            for(int j = 0; j < t.length(); j++)
            {
                if( t[j] != '.')
                    cout << t[j];
            }
            for(int j=0 ;j < n-t.length()+2; j++)
            {
                cout << "0";
            }
        }
        else{
         for(int j = 0; j<n+2; j++)
         {
             if(t[j] != '.')
                 cout << t[j];
         }
         cout << ".";
         for(int j= n+2; j < t.length(); j++)
            cout << t[j];
        }
    }
    return 0;
}

柳婼的解法:

#include <iostream>
using namespace std;
int main() {
 string s;
 cin >> s;
 int i = 0;
 while (s[i] != 'E') i++;
 string t = s.substr(1, i-1);
 int n = stoi(s.substr(i+1));
 if (s[0] == '-') cout << "-";
 if (n < 0) {
        cout << "0.";
         for (int j = 0; j < abs(n) - 1; j++) cout << '0';
         for (int j = 0; j < t.length(); j++)
         if (t[j] != '.') cout << t[j];
 }
 else {
        cout << t[0];
         int cnt, j;
         for (j = 2, cnt = 0; j < t.length() && cnt < n; j++, cnt++) cout <<
t[j];
        if (j == t.length()) {
                for (int k = 0; k < n - cnt; k++) cout << '0';
        }
        else {
                cout << '.';
                 for (int k = j; k < t.length(); k++) cout << t[k];
        }
 }
 return 0;
}

PAT甲级——1073 Scientific Notation (20分)的更多相关文章

  1. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  2. PAT Advanced 1073 Scientific Notation (20 分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  3. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

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

  4. 【PAT甲级】1073 Scientific Notation (20 分)

    题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...

  5. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  6. 1073. Scientific Notation (20)

    题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...

  7. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  8. PAT 甲级 1046 Shortest Distance (20 分)(前缀和,想了一会儿)

    1046 Shortest Distance (20 分)   The task is really simple: given N exits on a highway which forms a ...

  9. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

随机推荐

  1. Flink笔记(二) DataStream Operator(数据流操作)

    DataStream Source 基于文件 readTextFile(path) 读取 text 文件的数据 readFile(fileInputFormat, path) 通过自定义的读取方式, ...

  2. 公告上下滚动基于Jquery

    前提  需要引入jquery  如果你用的单位不是px  修改的同时红色部分需保持一致 <!DOCTYPE html> <html> <head> <meta ...

  3. tcp协议与dup协议知识总结

    在工作之余用xmind总结了一些UDP协议与TCP协议的知识点,如果有需要可以通过下方的留言,分享xmind文件和xmind软件.

  4. UVA - 11892 ENimEN(博弈)

    题意:有n堆石子,两个人拿,拿走最后的石子的人赢,poopi先拿,条件是,每个人必须从另外一个人最后拿过的石子堆中取石子,若那堆石子被拿没了,才可以自由地拿其他堆.要求每次拿的石子数不能为0.问谁赢. ...

  5. MySQL8.0安装caching_sha2_password问题

    MySQL安装之后无法用工具连接上本地数据库 详情原因可见: https://mysqlserverteam.com/mysql-8-0-4-new-default-authentication-pl ...

  6. oracle(5)--DQL查询语句

    DQL 数据查询语句(data query language) 1.查询条件符号: < ,  > ,  = ,    <= ,  >= ,    != ,  < > ...

  7. cf 525D.Arthur and Walls

    判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好.(这种处理也是挺神奇的2333%%题解) #include<bits/stdc++.h& ...

  8. java web实现在线编辑word,并将word导出(一)

    前段时间领导交代了一个需求:客户需要一个能够web在线编辑文字,如同编辑word文档一样,同时能够将编辑完成的内容导出为word文档并下载到本地. 我们选择了前台使用富文本插件的形式用于编辑内容,使用 ...

  9. 文献阅读报告 - Context-Based Cyclist Path Prediction using RNN

    原文引用 Pool, Ewoud & Kooij, Julian & Gavrila, Dariu. (2019). Context-based cyclist path predic ...

  10. 翻翻棋(找规律问题)(FZU Problem 2230)

    题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...