zoukankan      html  css  js  c++  java
  • Barnicle

    Barnicle

    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
    分析:注意0.0e0;
    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #include <ext/rope>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define vi vector<int>
    #define pii pair<int,int>
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    const int maxn=1e5+10;
    const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
    using namespace std;
    using namespace __gnu_cxx;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m,now,len,cnt;
    string a,ans;
    int main()
    {
        int i,j,k,t;
        cin>>a;
        len=a.length();
    
    
        //特判;
        if(a=="0.0e0")return 0*puts("0");
    
        //找分隔符e;
        for(now=0;a[now]!='e';now++);
    
        //计算进位;
        for(i=now+1;i<len;i++)cnt=cnt*10+a[i]-'0';
        ans+=a[0];
    
        //进位;
        for(i=0;i<cnt&&a[2+i]!='e';i++)ans+=a[2+i],now=2+i;
    
        if(i!=cnt)for(;i<cnt;i++)ans+='0';//不足补0;
        else
        {
            ans+='.';                       //小数部分;
            for(;a[2+i]!='e';i++)ans+=a[2+i],now=2+i;
        }
    
        //处理答案前多余0;
        for(i=0;ans[i]=='0';i++);
        if(ans[i]=='.')i--;
        ans.erase(0,i);
    
        //处理小数点后末尾0;
        len=ans.length();
        if(count(ans.begin(),ans.end(),'.')!=0)
        {
            len=ans.length();
            for(i=len-1;i>=0&&(ans[i]=='0'||ans[i]=='.');i--);
            ans=ans.substr(0,i+1);
        }
        cout<<ans<<endl;
        //system ("pause");
        return 0;
    }
    
    
    
    
    
    
    
    
     
  • 相关阅读:
    uboot nand erase 的显示错误修复
    Sougo for linux install.
    S3C6410移植uboot2010.3(2)基本的启动信息修改
    S3C6410移植uboot2010.3(4)uboot的dnw功能添加
    S3C6410移植uboot2010.3(3)正常化配置
    ubuntu乱码修复
    应老婆点(20070705 13:11:34)(新浪)
    克己慎独 2008923 13:32:00 (21ic)
    信任(20061229 14:16:32)(新浪)
    不要轻易承诺 2008926 14:42:00 (21ic)
  • 原文地址:https://www.cnblogs.com/dyzll/p/5672519.html
Copyright © 2011-2022 走看看