10370 - Above Average

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Oh.... NO..

Post by Obaida » Thu Jan 31, 2008 6:16 am

Still got WA. help me...
[/code]
#include<stdio.h>
int main()
{
long long int n,x[1000],m,i,j;
long double sum,count,ans,ave;
scanf("%lld",&m);
for(j=1;j<=m;i++)
{
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
scanf("%lld",&x);
}
sum=0;
for(i=1;i<=n;i++)
{
sum=sum+x;
}
ave=0;
count=0;
ave=sum/n;
for(i=1;i<=n;i++)
{
if(x>ave)
count++;
}
ans=0;
ans=(count/n)*100;
printf("%.3Lf%%\n",ans);
}
return 0;
}[/quote]
try_try_try_try_&&&_try@try.com
This may be the address of success.

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil » Tue Feb 12, 2008 8:32 pm

Change this line

Code: Select all

for(j=1;j<=m;i++)

Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Still..WA

Post by Obaida » Thu Feb 14, 2008 10:38 am

Crazzzzzzzzzzzzzzy... Still got WA......... :evil:
try_try_try_try_&&&_try@try.com
This may be the address of success.

valkov
New poster
Posts: 20
Joined: Tue Jul 20, 2010 3:11 pm

Re: 10370 - Above Average

Post by valkov » Sat Sep 11, 2010 8:19 pm

Just got AC on this problem :)
Some tips for those of you who want quick and dirty solution:
1. Use float or double ( I used double ) for calculating the average score and the percentage
2. In order to output the percentage use something like this:

Code: Select all

cout << fixed << setprecision(3) << percentage << "%" << endl;

which will make your life easier :)
3. Have fun :)

Daniel.Diaz
New poster
Posts: 1
Joined: Thu Dec 30, 2010 8:28 am

Re: 10370 - Above Average Runtime error ?:S

Post by Daniel.Diaz » Thu Dec 30, 2010 8:37 am

Why i have runtime error, :S i dont understand

Code: Select all


#include<stdio.h>

int main()
{
    int datos[50],casos,n,i,sum,cont,j;
    float media;
    
    scanf("%d",&casos);
    for(j=0;j<casos;j++){
                   scanf("%d",&n);
                   cont=sum=0;
                   for(i=0;i<n;i++){
                              scanf("%d",&datos[i]);
                              sum+=datos[i];
                   }
                   media=(float)sum/(float)n;
                   for(i=0;i<n;i++){
                              if(datos[i]>media)
                                 cont++;      
                   }
                   printf("%.3f%%\n",((float)cont*100)/((float)n));

    }
    
    
    return 0;
}


WEREWOLFzubair09
New poster
Posts: 1
Joined: Mon Jun 20, 2011 12:34 am

10370 - above average :

Post by WEREWOLFzubair09 » Mon Jun 20, 2011 12:59 am

10370 - above average : I am getting runtime error.. but i see no problem. WHY?? :x :evil: :roll:
here is my code-->

Code: Select all

    #include<stdio.h>
    #include<iostream>

    using namespace std;

    float avrg(int i, int []);



    int main()
    {
    int i,j[20][20];
    scanf("%d",&i);
    for(int a=0;a<i;a++)
    {
         scanf("%d",&j[a][0]);
         for(int b=1;b<=j[a][0];b++)
         {
            scanf("%d",&j[a][b]) ;
         }
    }

    for(int a=0;a<i;a++)
    {
        printf("%.3f%%\n",avrg(j[a][0],j[a]));

    }

    return 0;
    }


    float avrg(int i,int ary[])
    {
        float avg;
        int sum=0,count=0;
        for(int a=1;a<=i;a++)
        {
            sum+=ary[a];
        }
        avg=(float)(sum/(float)i);
        for(int a=1;a<=i;a++)
        {
         if(ary[a]>avg) count++;
        }

        avg=(float)((float)count/(float)i)*100;
        return avg;
    }



shanto_0321
New poster
Posts: 4
Joined: Sun Sep 11, 2011 8:12 am

Re: 10370 - above average :

Post by shanto_0321 » Sun Sep 11, 2011 4:55 pm

when we use long double .?can you help me.please

Saiful Islam
New poster
Posts: 1
Joined: Wed Sep 14, 2011 5:03 pm

Re: 10370 - Above Average runtime error???

Post by Saiful Islam » Wed Sep 14, 2011 5:09 pm

why am i getting runtime error...plz help me out..here is my code..
#include<stdio.h>

int main()

{
int t,n,arr[100],i,j,count;
double avg,res,numb;
char ch='%';

scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
avg=0;
for(j=0;j<n;j++)
{
scanf("%d",&arr[j]);
avg+=arr[j];
}
numb=j;
avg/=numb;
count=0;
for(j=0;j<n;j++)
{
if(arr[j]>avg)
count++;
}
res=(count*100)/numb;
printf("%.3lf%c\n",res,ch);



}
return 0;

}

reza_uranium
New poster
Posts: 2
Joined: Fri Feb 01, 2013 4:12 pm

Re: 10370 - Above Average

Post by reza_uranium » Fri Feb 01, 2013 4:19 pm

getting run time error....how...why :o

#include <stdio.h>

int main()
{
int i,j,m,n,a[100],sum,std;
double average,percentage;

scanf("%d",&n);

for(i=1;i<=n;i++){
scanf("%d",&m);
sum=0;
std=0;
for(j=0;j<m;j++){
scanf("%d",&a[j]);
sum+=a[j];
}
average=sum/m;
for(j=0;j<m;j++){
if(average<a[j]){
std++;
}
}
percentage=(std*m)/100.0;
printf("%.3lf%%\n",percentage);
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10370 - Above Average

Post by brianfry713 » Fri Feb 01, 2013 9:46 pm

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

Ranit
New poster
Posts: 2
Joined: Fri May 31, 2013 8:09 pm

Re: 10370 - Above Average

Post by Ranit » Fri May 31, 2013 8:26 pm

10370 - Above Average

why am i getting runtime error??? plz say?!!! :(

#include <stdio.h>
int main()
{
int c, k, j = 0, count, i;
int a, b;
long int inp[500];
double s, avg;
scanf("%d", &b);
for(i = 0; i < b; i++){
scanf("%d", &a);
count = 0;
c = 0;
for(k = 0; k < a; k++) {
scanf("%d", &inp[count]);
c += inp[count++];
}
avg = c / a;
count = 0; j = 0;
for(k = 0; k < a; k++) {
if(inp[count++] > avg)
j++;
}
s = ((double)j /(double) a)* 100;
printf("%2.3lf%%\n", s);

}
return 0;
}

when i increased the array size to 1000 i, i 've got a Wrong Answer?!!
plz help me!!!! :oops:

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10370 - Above Average

Post by brianfry713 » Tue Jun 11, 2013 11:18 pm

Change line 6 to:
int inp[1000];
Check input and AC output for thousands of problems on uDebug!

rloursua
New poster
Posts: 4
Joined: Tue Feb 11, 2014 5:52 pm

Re: 10370 - Above Average

Post by rloursua » Sat Feb 22, 2014 7:45 am

Could somebody help me please. I do not get what is wrong with my code.
I tried removing and putting the blank link after the output but both came out as WA

Code: Select all

#include <stdio.h>
#include <string.h>

int main ()
{
	int test = 0;
	int tc = 0;	
	int num = 0;	
	int grades[1000];
	int i=0;
	scanf("%d",&test);
	
	for(tc=0;tc<test;tc++)
	{
		scanf("%d",&num);
		double ave = 0;
		
		for(i=0;i<num;i++)
		{
			scanf(" %d",&grades[i]);
			ave = ave + grades[i];
		}
		
		int count = 0;
		ave = ave / num;
		for(i=0;i<num;i++)
		{
			if(grades[i]>ave)
				count++;
		}
		
		double x=count;
		
		if(tc!=test-1)
			printf("%.3lf%%\n",x/num*100);
		else
			printf("%.3lf%%",x/num*100);
	}
	
	
	return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10370 - Above Average

Post by brianfry713 » Mon Feb 24, 2014 10:52 pm

Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

alex8078
New poster
Posts: 2
Joined: Thu Jan 08, 2015 8:05 pm

10370 - above average

Post by alex8078 » Thu Jan 08, 2015 8:15 pm

Hello, everybody. I got WA for my code but I don't know why.
Please help me :) thx~

Code: Select all

#include<iostream>
#include<iomanip>
#include<queue>
#include<stdio.h>
using namespace std;


void above_score(const int num,const int total, priority_queue<int>& q)
{
	int cnt = 0;
	
	while(!q.empty())
	{
		if((q.top()*num)<=total) break;
		else
		{
		  q.pop();	
		  cnt++;	
		}
	}
	double ratio = (double(cnt)/num)*100;
	cout<<setprecision(3)<<setiosflags(ios::fixed)<<ratio<<"%"<<endl;
	/*printf("%.3lf%%\n",ratio);*/
}


int main(void)
{
   int case_num;
   int total_score = 0;
   int score_num;
   int score;
   
   	
   while(cin>>case_num)
   {
	  priority_queue<int> score_list;
	  for(unsigned i=0;i<case_num;++i)  
	  {
		  cin>>score_num;
		  total_score = 0;
		  for(unsigned j=0;j<score_num;++j)
		  {
			 cin>>score; 
			 total_score+= score;
			 score_list.push(score); 
		  }
		  if(score_list.size()>1)
		    above_score(score_num,total_score,score_list);
		  else 
			cout<<"0.000%"<<endl;
	  } 
	    
   }
	
	return 0;
}

Post Reply

Return to “Volume 103 (10300-10399)”