Wednesday, May 24, 2017

uva problem solution 10370 - Above Average


problem link :

Discuss: In this problem you have to make the average of numbers then check linearly which number is greater then the average then just make percentage with total numbers and above the average number.

try yourself before see the code


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i,j,p,q,r,cnt,t,l,m,sum;
   double a,b,f;
   vector<int>vec;
    cin >>t;
    for(l=0;l<t;l++)
    {
    cnt=0;
    sum=0;
    vec.clear();
      cin >>n;
      for(i=0;i<n;i++)
      {
         cin >>m;
         vec.push_back(m);
         sum+=m;
      }
      b=double(sum)/double(n);
      for(i=0;i<n;i++)
      {
        if(vec[i]>b)
         cnt++;
      }
      b=cnt/(double)n;
      f=b*100.0;
      printf("%.3lf%%\n",f);
    }
    return 0;


}


No comments:

Post a Comment