zoukankan      html  css  js  c++  java
  • Codeforces 679B. Barnicle 模拟

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

    题目链接:http://codeforces.com/contest/697/problem/B

    题意:参照样例
    思路:模拟
    注意一些特殊情况。2.0e0输出2;0.00e0输出0;0.0001e2输出0.01。注意消去前导0,后导0。

    代码:
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int i;
        int a,b;
        char ch;
        int d[200];
        scanf("%d",&a);
        getchar();
        int len=0;
        while((ch=getchar())&&ch!='e')
            d[len++]=ch-'0';
        for(i=len-1; i>=0; i--)
            if(d[i]) break;
        len=i+1;
        scanf("%d",&b);
        getchar();
        int sign=0;
        if(a!=0)
        {
            cout<<a;
            sign=1;
        }
        for(i=0; i<len&&i<b; i++)
        {
            if(sign==0&&d[i]==0) continue;
            else
            {
                cout<<d[i];
                sign=1;
            }
        }
        if(sign!=0&&len<b)
            for(i=len; i<b; i++) cout<<"0";
        else if(len>b)
        {
            if(sign) cout<<".";
            else cout<<"0.";
            for(i=b; i<len; i++) cout<<d[i];
        }
        else if(sign==0) cout<<"0";
        cout<<endl;
        return 0;
    }
    View Code
    I am a slow walker,but I never walk backwards.
  • 相关阅读:
    使用四元数点乘比较插值是否即将完成
    ShadowGun Demo学习(非技术向)
    测试-关于Unity获取子层级内容的几种接口(Transform FindChild, Component GetComponentInChildren,...)
    Javascript事件模型系列(二)事件的捕获-冒泡机制及事件委托机制
    Javascript事件模型系列(一)事件及事件的三种模型
    在代码中设置IE9的默认文档模式
    如何在博客园的文章/随笔中添加可运行的js代码
    jquery插件:仿百度首页可展开收起的消息提示控件
    有“镜头感”的网页是如何实现的
    HTML5 history API实践
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/5673307.html
Copyright © 2011-2022 走看看