当前位置:网站首页>P2393 yyy loves Maths II

P2393 yyy loves Maths II

2022-06-26 13:03:00 A program ape who smashes the keyboard

P2393 yyy loves Maths II

# yyy loves Maths II

## Background

Last time konjak redbag Can handle yyy I'm so angry ,yyy Said he was just a pupil , Konnyaku redbag Don't pit him this time .

## Title Description

redbag Give it to yyy A lot of numbers , want yyy Calculate the sum of these numbers .

Must be fast ,redbag Only for yyy $1$ The second time !!!

## Input format

a line , A lot of numbers .

## Output format

a line , A real number ( Round to the nearest $5$ Decimal place ), Represents the sum of these numbers .

## Examples #1

### The sample input #1

```
1
```

### Sample output #1

```
1.00000
```

## Tips

about $100\%$ The data of , All numbers $ \le 233,333,333 $, Ensure that there are at most... After the decimal point $6$ digit , Most in common $5\times 10^4$ Number .

 【70 Code division 】

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
double n,ans;
signed main()
{
	while(cin>>n)ans+=n;
	cout<<fixed<<setprecision(5)<<ans;	
	return 0;
}

When I finished, I still exclaimed that the problem was too simple , The result is ......

Pay attention to it

【AC Code 】 

  Then the next data suddenly thought that the accuracy was not enough , Switch to long double It's still not right . think it over and over again It suddenly occurred to me that I could convert decimals into integers to add , therefore ......

 

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e6;
long double n,ans;
signed main()
{
	while(cin>>n)ans+=n*N;
	cout<<fixed<<setprecision(5)<<ans/N;	
	return 0;
}
Pay attention to it

 

 

原网站

版权声明
本文为[A program ape who smashes the keyboard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261216573424.html