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)
  • 相关阅读:
    Spring源码情操陶冶-AOP之Advice通知类解析与使用
    Spring源码情操陶冶-AOP之ConfigBeanDefinitionParser解析器
    TCP/IP__Cisco的3层分层模型
    网际互连__冲突域和广播域
    网际互连__数据包结构
    网际互连__散知识点
    网际互连__单播、组播、广播
    网际互连__以太网端口
    网际互连__以太网
    网际互连__TCP/IP三次握手和四次挥手
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12819836.html
Copyright © 2011-2022 走看看