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. String巩固

    About String in Java 如今做了一个重大决定,不定期温习The Basement Of Java String对象的认知简述 首先 String不属于 8种基本数据类型, Strin ...

  2. 逆向-PE重定位表

    重定位表 ​ 当链接器生成一个PE文件时,会假设这个文件在执行时被装载到默认的基地址处(基地址+RVA就是VA).并把code和data的相关地址写入PE文件.如果像EXE一样首先加载就是它image ...

  3. com.alibaba.druid.pool.DruidDataSource

    https://www.cnblogs.com/wuyun-blog/p/5679073.html DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PR ...

  4. 通过while循环一步步实现九九乘法表

    # 打印#做出@列的效果height = int(input("height: ")) #用户输入一个高度 num_height = heightwhile num_height ...

  5. UVA - 11093 Just Finish it up(环形跑道)(模拟)

    题意:环形跑道上有n(n <= 100000)个加油站,编号为1~n.第i个加油站可以加油pi加仑.从加油站i开到下一站需要qi加仑汽油.你可以选择一个加油站作为起点,起始油箱为空(但可以立即加 ...

  6. 读书笔记 - js高级程序设计 - 第十五章 使用Canvas绘图

    读书笔记 - js高级程序设计 - 第十三章 事件   canvas 具备绘图能力的2D上下文 及文本API 很多浏览器对WebGL的3D上下文支持还不够好   有时候即使浏览器支持,操作系统如果缺缺 ...

  7. Java算法练习—— Z 字形变换

    题目链接 题目描述 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L ...

  8. 当chart图遇上bootstrap的TAB切换 无宽高问题?

    .tab-content > .tab-pane, .pill-content > .pill-pane {    display: block; /* undo display:none ...

  9. 51Nod-1072-威佐夫游戏

    有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取.拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出2堆石子的数量, ...

  10. 吴裕雄--天生自然 JAVASCRIPT开发学习:事件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...