Advertisement
Saleh127

Untitled

May 3rd, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6. ll t=1,x,a,b,c,d,e,f,i,j,k,l,m,n,o,sum;
  7. while(scanf("%lld",&x))
  8. {
  9. sum=0;
  10. if(x==0) return 0;
  11. for(i=0;i<x;i++)
  12. {
  13. scanf("%lld",&b);
  14. sum+=b;
  15. }
  16. printf("Case %lld:\n",t++);
  17. if(abs(sum)%x==0)
  18. {
  19. if(sum<0) printf("- ");
  20. printf("%lld\n",abs(sum)/x);
  21. }
  22. else
  23. {
  24. if(abs(sum)%x!=0 && abs(sum)/x>=1)
  25. {
  26. c=x;
  27. d=abs(sum);
  28. e=__gcd(c,d);
  29. c=c/e;
  30. d=d/e;
  31. if(sum<0)
  32. {
  33. printf(" %lld\n",d%c);
  34. printf("- %lld-\n",d/c);
  35. printf(" %lld\n",c);
  36. }
  37. else if(sum>0)
  38. {
  39. printf(" %lld\n",d%c);
  40. printf("%lld-\n",d/c);
  41. printf(" %lld\n",c);
  42. }
  43. }
  44. else
  45. {
  46. c=x;
  47. d=abs(sum);
  48. e=__gcd(c,d);
  49. c=c/e;
  50. d=d/e;
  51. if(sum<0)
  52. {
  53. printf(" %lld\n",d);
  54. printf("- -\n");
  55. printf(" %lld\n",c);
  56. }
  57. else if(sum>0)
  58. {
  59. printf("%lld\n",d);
  60. printf("%-\n");
  61. printf("%lld\n",c);
  62. }
  63. }
  64. }
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement