Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4
- 15.00
- 15.01
- 3.00
- 3.01
- $11.99
- #include <iostream>
- #include <iomanip>
- using namespace std;
- float two_precision(float n){
- return n - float((n*100.0-(int)(n*100))/100.0);
- }
- int main(){
- int n; cin >> n;
- float *v, sum, avg, dif;
- while(n){
- sum = dif = 0.0;
- v = new float[n];
- for(int i = n-1; i >= 0; i--){
- cin >> v[i];
- sum += v[i];
- }
- avg = (1.0*sum)/n;
- for(int i = n-1; i >= 0; i--)
- if(two_precision(v[i]-avg > 0))
- dif = two_precision(dif + two_precision(v[i]-avg));
- cout << '$';
- cout << fixed << setprecision(2) << dif << endl;
- delete v;
- cin >> n;
- }
- return 0;
- }
- 5
- 15.04
- 15.17
- 30.32
- 39.99
- 78.99
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement