zoukankan      html  css  js  c++  java
  • Codeforces Round #362 (Div. 2) B 模拟

    B. Barnicle
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

    Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.

    Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

    Input

    The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.

    a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

    Output

    Print the only real number x (the desired distance value) in the only line in its decimal notation.

    Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.

    Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).

    Examples
    Input
    8.549e2
    Output
    854.9
    Input
    8.549e3
    Output
    8549
    Input
    0.33e0
    Output
    0.33

    题意:x = A × 10B 将科学计数法 转为为普通实数 不能有前导零 不能有后置零
    hack数据
    0.0e0
    0
    2.40000e2
    240


    题解:模拟 注重细节处理 考虑要细致

     1 #include<bits/stdc++.h>
     2 #define ll __int64
     3 #define mod 1e9+7
     4 #define PI acos(-1.0)
     5 #define bug(x) printf("%%%%%%%%%%%%%",x);
     6 using namespace std;
     7 char a[1005];
     8 char b[1005];
     9 int main()
    10 {
    11     cin>>a;
    12     int len=strlen(a);
    13     int wei=0;
    14     int flag;
    15     for(int i=0;i<len;i++)//找到小数点
    16     {
    17         if(a[i]=='.')
    18             flag=i;
    19     }
    20     int gg=1;
    21     int zha=0;
    22     for(int j=len-1;j>flag;j--)//进多少位
    23     {
    24         if(a[j]=='e')
    25           {
    26               a[j]='';
    27               break;
    28           }
    29         wei=wei+(a[j]-'0')*gg;
    30         gg*=10;
    31         a[j]='';
    32     }
    33 
    34      len=strlen(a);
    35     int weishu=len-(flag+1);//现有小数位数
    36     if(wei==0&&weishu==1&&a[2]=='0')//特判数据
    37     {
    38         cout<<a[0]<<endl;
    39         return 0;
    40     }
    41     if(wei<weishu)
    42     {
    43         for(int j=flag;j<flag+wei;j++)
    44             a[j]=a[j+1];
    45         a[flag+wei]='.';
    46     }
    47     if(wei==weishu)
    48     {
    49          for(int j=flag;j<flag+wei;j++)
    50             a[j]=a[j+1];
    51             a[flag+wei]='';
    52     }
    53     if(wei>weishu)
    54     {
    55         for(int j=flag;j<flag+weishu;j++)
    56             a[j]=a[j+1];
    57         for(int j=flag+weishu;j<flag+wei;j++)
    58             a[j]='0';
    59         a[flag+wei]='';
    60     }
    61     int len1=strlen(a);
    62     int aaa=0;
    63     int zzz=0;
    64     if(wei<weishu)//去掉后置零
    65     {
    66         for(int j=len1-1;j>0;j--)
    67       {
    68         if(zzz)
    69         break;
    70         if(a[j]!='0')
    71             zzz=1;
    72         if(a[j]=='0'||a[j]=='.')
    73             a[j]='';
    74 
    75       }
    76     }
    77     for(int i=0;i<len1;i++)//去掉前导零
    78     {
    79         if(a[i]!='0'||a[i+1]=='.')
    80             aaa=1;
    81         if(aaa)
    82         {
    83             cout<<a[i];
    84         }
    85     }
    86     cout<<endl;
    87     return 0;
    88 }


  • 相关阅读:
    springboot使用war包部署到外部tomcat
    html只允许输入的数据校验,只允许输入字母汉字数字等
    转:执行ajax加载页面中的js
    php 解析xml 的四种方法(转)
    Php 获取xml中的节点值
    php中DOMDocument简单用法(XML创建、添加、删除、修改)
    PHP对XML文件操作详细
    转载 PHP 程序员学数据结构与算法之《栈》
    php读取二进制流(C语言结构体struct数据文件)的深入解析
    关于php和C语言接口的结构传递问题,udp,tcp通信
  • 原文地址:https://www.cnblogs.com/hsd-/p/5674705.html
Copyright © 2011-2022 走看看