Budget (思维)

Budget

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

这道题m的范围是1e18,把每个m都计算不好求,只需要把每个m的小数点位后第三位四舍五入之后(入是+,舍是-),最后得出的就是误差。

#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
	int T;
	
	while(~scanf("%d",&T)){
		
		double sum=0;
		for(int i=0;i<T;i++){
		string a;
			cin>>a;
			int l=a.size();
			int ll;
			for(int j=0;j<l;j++){
				if(a[j]=='.') ll=j;
			}
//			cout<<a[ll+3]<<endl;
			if(a[ll+3]>='5'){
				sum+=('9'+1-a[ll+3]);
			}
			else sum-=(a[ll+3]-'0');
//			cout<<"SUM:"<<sum<<endl;
		}
//		printf("%lf",sum);
		printf("%.3lf\n",sum/1000);
	}
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值