zoukankan      html  css  js  c++  java
  • 1073 Scientific 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

    题意:

      将数字由科学计数法表示改为普通数字表示方法。

    思路:

      模拟。

    Code:

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 int main() {
     6     string in;
     7     cin >> in;
     8     if (in[0] == '-') cout << '-';
     9     int pos = in.find('E');
    10     string coef = in.substr(1, pos - 1);
    11     string exp = in.substr(pos + 2);
    12     int e = stoi(exp);
    13     int c = stoi(coef);
    14     int len = coef.length();
    15     if (in[pos + 1] == '+') {
    16         if (len - 2 > e) {
    17             cout << coef[0];
    18             for (int i = 2; i < len; ++i) {
    19                 if (i == e + 2) cout << '.';
    20                 cout << coef[i];
    21             }
    22             cout << endl;
    23         } else {
    24             cout << coef[0];
    25             for (int i = 2; i < len; ++i) cout << coef[i];
    26             for (int i = 0; i < e - len + 2; ++i) cout << '0';
    27         }
    28     } else {
    29         if (e == 0) cout << 1 << endl;
    30         for (int i = 0; i < e; ++i) {
    31             cout << '0';
    32             if (i == 0) cout << '.';
    33         }
    34         cout << coef[0];
    35         for (int i = 2; i < len; ++i) cout << coef[i];
    36         cout << endl;
    37     }
    38     return 0;
    39 }
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    MySQL讲义
    python使用matplotlib在一个图形中绘制多个子图以及一个子图中绘制多条动态折线问题
    python爬虫登陆网页版腾讯课堂
    父子组件之间相互传值
    echarts图中使用到的属性及对应的作用,饼图实例、折线图实例
    vue get类型接口调用方式
    javaScript前进后退点击事件
    vue页面跳转
    如何修改vant组件中原有样式?
    Module not found: Error: Can't resolve 'less-loader' in '文件位置'报错解决
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12819836.html
Copyright © 2011-2022 走看看