Budget hdu-6575

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

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int sum=0;
		for(int i=0;i<n;i++)
		{
			string ss;int ll;
			cin>>ss;
			for(int j=0;j<ss.length();j++)
				if(ss[j]=='.') ll=j;
			if(ss[ll+3]>='5') sum=sum+'9'-ss[ll+3]+1;
			else sum=sum-(ss[ll+3]-'0');
		}
	printf("%.3lf\n",sum*0.001);
	}
	return 0;
}
发布了31 篇原创文章 · 获赞 0 · 访问量 339

猜你喜欢

转载自blog.csdn.net/weixin_44828107/article/details/103000489