Guest User

Untitled

a guest
Jun 24th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /*The input file consists of several blocks of data. Each block starts with the number of candy packets N(1<= N <=10000)
  2. followed by N integers (each less than 1000)in separate lines,
  3. giving the number of candies in each packet. After the last block of data there is the number -1. */
  4. #include<iostream>
  5. #include <cstdlib>
  6. #include<string.h>
  7. using namespace std;
  8. int main()
  9. {
  10. long long count=0,j,i,sum=0,l,temp,t;
  11. double k;
  12. cin>>k;
  13. while(k!=-1&&k<=10000)
  14. {
  15. int n=(int)k;
  16. int a[1005];
  17. for(i=0;i<n;i++)
  18. {
  19. cin>>a[i];
  20. sum+=a[i];
  21. }
  22. temp=sum/n;
  23. t=n*temp;
  24. // int temp1=(int)temp;
  25. // l=sum%n;
  26. if(t==sum)
  27. {
  28. for(j=0;j<n;j++)
  29. {
  30. if(a[j]>temp)
  31. count+=a[j]-temp;
  32. }
  33. cout<<count<<endl;
  34. }
  35. else
  36. cout<<-1;
  37. count=0;
  38. sum=0;
  39. cin>>k;
  40. }
  41.  
  42. cin.clear();
  43. cin.ignore(255,'\n');
  44. cin.get();
  45.  
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment