Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. 4
  2. 15.00
  3. 15.01
  4. 3.00
  5. 3.01
  6.  
  7. $11.99
  8.  
  9. #include <iostream>
  10. #include <iomanip>
  11.  
  12. using namespace std;
  13.  
  14. float two_precision(float n){
  15. return n - float((n*100.0-(int)(n*100))/100.0);
  16. }
  17.  
  18. int main(){
  19.  
  20. int n; cin >> n;
  21. float *v, sum, avg, dif;
  22.  
  23. while(n){
  24.  
  25. sum = dif = 0.0;
  26. v = new float[n];
  27. for(int i = n-1; i >= 0; i--){
  28. cin >> v[i];
  29. sum += v[i];
  30. }
  31.  
  32. avg = (1.0*sum)/n;
  33.  
  34. for(int i = n-1; i >= 0; i--)
  35. if(two_precision(v[i]-avg > 0))
  36. dif = two_precision(dif + two_precision(v[i]-avg));
  37.  
  38. cout << '$';
  39. cout << fixed << setprecision(2) << dif << endl;
  40.  
  41. delete v;
  42. cin >> n;
  43. }
  44.  
  45. return 0;
  46. }
  47.  
  48. 5
  49. 15.04
  50. 15.17
  51. 30.32
  52. 39.99
  53. 78.99
  54. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement