Codeforces-697B-Barnicle(模拟)

A - Barnicle
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit

Status

Practice

CodeForces 697B
Description
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).

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

小心0.0e0这组数据

代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<iomanip>
using namespace std;
const int maxn=2222;
int main()
{
    char str1[maxn];//接收数据
    char str2[maxn];//存储处理过的数据
    scanf("%s",str1);
    int A=str1[0]-'0';//获取小数点前的A
    int len_str2=0;//小数位数
    for(int i=2; str1[i]!='e'; i++)
        str2[len_str2++]=str1[i];//转存小数点后,e之前的部分
    int B=0;
    int len_str1=strlen(str1);
    for(int i=len_str1-1,flag=1; str1[i]!='e'; i--,flag*=10) //获取B
        B+=(str1[i]-'0')*flag;
    printf("%d",A);
    if(B==0)
    {
        if(len_str2==1&&str2[0]=='0')//0.0e0的情况
            return 0;
        printf(".");//接着原样输出
        for(int i=0; i<len_str2; i++)
            printf("%c",str2[i]);
        printf("\n");
        return 0;
    }
    int i=0;//已输出数量 len_str2
    int j=0;//待输出数量 B
    for(; i<len_str2&&j<B; i++,j++)
        printf("%c",str2[i]);
    if(i==len_str2&&j==B)//恰好完全输出
        return 0;
    if(j<B)//如果str2中元素不足,用0补齐
    {
        for(; j<B; j++)
            printf("0");
        printf("\n");
        return 0;
    }
    if(i<len_str2)//str2中还有未输出元素
    {
        printf(".");//加上小数点后原样输出
        for(; i<len_str2; i++)
            printf("%c",str2[i]);
        printf("\n");
        return 0;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值