zoukankan      html  css  js  c++  java
  • pat1073. Scientific Notation (20)

    1073. Scientific Notation (20)

    时间限制
    100 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    HOU, Qiming

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

    提交代码

    科学计数法。

     1 #include<cstdio>
     2 #include<stack>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<stack>
     6 #include<set>
     7 #include<map>
     8 using namespace std;
     9 string trans(string s){
    10     int i=1;
    11     while(i<s.length()){//有效数位
    12         if(s[i]=='E'){
    13             break;
    14         }
    15         i++;
    16     }
    17     int index=++i;//指数符号位
    18 
    19     //cout<<index<<endl;
    20 
    21     i++;//指数开始
    22     int exp=0;
    23     //确定指数
    24     while(i<s.length()&&s[i]=='0'){//去掉前0
    25         i++;
    26     }
    27 
    28     //cout<<i<<endl;
    29 
    30     while(i<s.length()){//指数计算
    31         exp*=10;
    32         exp+=s[i]-'0';
    33         i++;
    34     }
    35 
    36     //cout<<exp<<endl;
    37 
    38     string ss;
    39     if(s[index]=='-'){
    40         i=exp-1;
    41         ss="0.";
    42         while(i){
    43             i--;
    44             ss=ss+'0';
    45         }
    46         ss=ss+s[1];
    47         for(i=3;s[i]!='E';i++){
    48             ss=ss+s[i];
    49         }
    50     }
    51     else{//
    52         ss=s[1];
    53         for(i=3;s[i]!='E'&&exp;i++,exp--){
    54             ss=ss+s[i];
    55         }
    56         if(s[i]=='E'){
    57             while(exp){
    58                 ss=ss+'0';
    59                 exp--;
    60             }
    61         }
    62         else{
    63             ss=ss+'.';
    64             while(s[i]!='E'){
    65                 ss=ss+s[i];
    66                 i++;
    67             }
    68         }
    69     }
    70     if(s[0]=='-'){
    71         ss='-'+ss;
    72     }
    73     return ss;
    74 }
    75 int main(){
    76     //freopen("D:\INPUT.txt","r",stdin);
    77     string s;
    78     cin>>s;
    79     //cout<<s<<endl;
    80     cout<<trans(s)<<endl;
    81     return 0;
    82 }
  • 相关阅读:
    oculus按键大全
    10 soundJs 初体验
    09 获取服务器时间
    08 基本数据类型转换
    07 如果再使用animateCC2018或者苹果系统使用animate时出现Uncaught ReferenceError: lib is not defined的错误
    AS3.0和php数据交互POST方式
    06 显示fps帧频
    05 js利用ajax向服务器发送请求并返回json值
    04 ajax执行php并传递参数
    03php拉取服务器信息并生成json
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4782315.html
Copyright © 2011-2022 走看看