Advertisement
erfanul007

LA 3012

Dec 9th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int dgtcnt(int k)
  5. {
  6. int z=0;
  7. while(k){
  8. k/=10;
  9. z++;
  10. }
  11. return z;
  12. }
  13.  
  14. int main()
  15. {
  16. int n,m,x,total,avg,gd,j=0;
  17. while(1){
  18. j++;
  19. cin>>n;
  20. if(n==0)
  21. break;
  22. total=0;
  23. for(int i=0;i<n;i++){
  24. cin>>x;
  25. total+=x;
  26. }
  27. cout<<"Case "<<j<<":"<<endl;
  28. if(total%n==0){
  29. if(total<0)
  30. printf("- ");
  31. avg=abs(total/n);
  32. cout<<avg<<endl;
  33. continue;
  34. }
  35. int mcnt=0,avgcnt=0,lcnt=0,hcnt=0,ucnt=0,tcnt=0,tmp;
  36. if(total<0)
  37. mcnt=2;
  38. total=abs(total);
  39. avg=total/n;
  40. m=total%n;
  41. gd=__gcd(m,n);
  42. n/=gd;
  43. m/=gd;
  44. avgcnt=dgtcnt(avg);
  45. lcnt=dgtcnt(m);
  46. hcnt=dgtcnt(n);
  47. ucnt=hcnt;
  48. tcnt=mcnt+avgcnt+hcnt;
  49. tmp=tcnt-lcnt;
  50. while(tmp--)
  51. cout<<" ";
  52. cout<<m<<endl;
  53. if(mcnt)
  54. cout<<"- ";
  55. if(avgcnt)
  56. cout<<avg;
  57. while(ucnt--)
  58. cout<<"-";
  59. cout<<endl;
  60. tmp=tcnt-hcnt;
  61. while(tmp--)
  62. cout<<" ";
  63. cout<<n<<endl;
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement