码迷,mamicode.com
首页 > 其他好文 > 详细

XDOJ_1060_浮点数

时间:2016-10-14 07:14:56      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

http://acm.xidian.edu.cn/problem.php?id=1060

 

这道题真是无语,被坑了好久,刚开始还以为只是浮点数的一点精度问题,在后面加了0.0000001。发现还是一直WA,问题应该是位数太长,后面的精度不准确地太厉害,只好用土方法过了。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[25];
int main()
{
    long long x;
    while(~scanf("%lld",&x))
    {
        int cnt = 0;
        if(x%10 >= 5)    x = x/10+1;
        else        x = x/10;
        if(x == 0)
        {
            printf("0.00\n");
            continue;
        }
        while(x)
        {
            a[++cnt] = x%10;
            x /= 10;
        }
        if(cnt > 2)
        {
            for(;cnt > 2;cnt--) printf("%d",a[cnt]);
        }
        else
        {
            printf("0");
        }
        printf(".");
        if(cnt == 1)    printf("0");
        for(;cnt > 0;cnt--) printf("%d",a[cnt]);
        printf("\n");
    }
    return 0;
}

 

XDOJ_1060_浮点数

标签:

原文地址:http://www.cnblogs.com/zhurb/p/5958758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!