Codeforces 697B Barnicle

B. Barnicle
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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

题目大意:给定字符串a.deb ,求a.d*10^b;数字变换后要考虑前导零、后面多余的零和不够位数补得零。如:1.0e0~~1 和 0.0e0~~0 和8.77056e6~~8770560,考虑的情况较多 ,本题主要考验代码的逻辑能力。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,ans[200];
    char ch;;
    scanf("%d",&a);//小数点前面的数
    getchar();
    int len=0;
    while((ch=getchar())&&ch!='e')
       ans[len++]=ch-'0';//ans数组是保存小数部分的数字
    for(i=len-1; i>=0; i--)
        if(ans[i]) break;//去掉后面的无效数字0
    len=i+1;
    scanf("%d",&b);//小数点要移动的位数
    getchar();
    int pos=0;
    if(a)
    {//如果a不为0,标记输出
        printf("%d",a);
        pos=1;
    }
    for(i=0; i<len&&i<b; i++)
    {
        if(pos==0&&ans[i]==0) continue;//如果a为0,去掉前面没用的0
        else
        {
            printf("%d",ans[i]);
            pos=1;
        }
    }
    if(pos&&len<b)//如果位数不够,其余位补0
        for(i=len; i<b; i++) printf("0");
    else if(len>b)
    {
        if(pos) printf(".");//如果a不为0,且有小数点,输出小数点
        else printf("0.");
        for(i=b; i<len; i++) printf("%d",ans[i]);//输出移动之后的小数部分
    }
    else if(pos==0) printf("0");//如果为0,
    printf("\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值