HDUOJ 6575 Budget

编程入门 行业动态 更新时间:2024-10-22 21:18:25

HDUOJ 6575 Budget

题目链接

Problem Description

Avin’s company has many ongoing projects with different budgets. His company records the budgets using numbers rounded to 3 digits after the decimal place. However, the company is updating the system and all budgets will be rounded to 2 digits after the decimal place. For example, 1.004 will be rounded down
to 1.00 while 1.995 will be rounded up to 2.00. Avin wants to know the difference of the total budget caused by the update.

Input

The first line contains an integer n (1 ≤ n ≤ 1, 000). The second line contains n decimals, and the i-th decimal ai (0 ≤ ai ≤ 1e18) represents the budget of the i -th project. All decimals are rounded to 3 digits.

Output

Print the difference rounded to 3 digits…

Sample Input

1
1.001
1
0.999
2
1.001 0.999

Sample Output

-0.001
0.001
0.000

比较容易想到的就是化成 i n t int int 扩大再减小来得到尾数,但是很明显数据很大,不能这么算(用 Java 大整数应该可以),所以换个思维,进不进位其实主要就看第三位,我们可以把数据当作字符串读入,直接判断最后一位即可,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char s[100];
int main(){
    while(~scanf("%d",&n)){
        double ans=0;
        while(n--){
            scanf("%s",s);
            int len=strlen(s);
            if(s[len-1]-'0'<=4) ans-=0.001*(s[len-1]-'0');
            else ans+=0.001*(10-(s[len-1]-'0'));
        }
        printf("%.3f\n",ans);
    }
}

更多推荐

HDUOJ 6575 Budget

本文发布于:2023-06-14 08:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HDUOJ   Budget

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!