Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int dgtcnt(int k)
- {
- int z=0;
- while(k){
- k/=10;
- z++;
- }
- return z;
- }
- int main()
- {
- int n,m,x,total,avg,gd,j=0;
- while(1){
- j++;
- cin>>n;
- if(n==0)
- break;
- total=0;
- for(int i=0;i<n;i++){
- cin>>x;
- total+=x;
- }
- cout<<"Case "<<j<<":"<<endl;
- if(total%n==0){
- if(total<0)
- printf("- ");
- avg=abs(total/n);
- cout<<avg<<endl;
- continue;
- }
- int mcnt=0,avgcnt=0,lcnt=0,hcnt=0,ucnt=0,tcnt=0,tmp;
- if(total<0)
- mcnt=2;
- total=abs(total);
- avg=total/n;
- m=total%n;
- gd=__gcd(m,n);
- n/=gd;
- m/=gd;
- avgcnt=dgtcnt(avg);
- lcnt=dgtcnt(m);
- hcnt=dgtcnt(n);
- ucnt=hcnt;
- tcnt=mcnt+avgcnt+hcnt;
- tmp=tcnt-lcnt;
- while(tmp--)
- cout<<" ";
- cout<<m<<endl;
- if(mcnt)
- cout<<"- ";
- if(avgcnt)
- cout<<avg;
- while(ucnt--)
- cout<<"-";
- cout<<endl;
- tmp=tcnt-hcnt;
- while(tmp--)
- cout<<" ";
- cout<<n<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement