10370 - Above Average
Moderator: Board moderators
Oh.... NO..
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]
[/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.
This may be the address of success.
Still..WA
Crazzzzzzzzzzzzzzy... Still got WA......... 

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 10370 - Above Average
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:
which will make your life easier
3. Have fun

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

-
- New poster
- Posts: 1
- Joined: Thu Dec 30, 2010 8:28 am
Re: 10370 - Above Average Runtime error ?:S
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;
}
-
- New poster
- Posts: 1
- Joined: Mon Jun 20, 2011 12:34 am
10370 - above average :
10370 - above average : I am getting runtime error.. but i see no problem. WHY??
here is my code-->



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;
}
-
- New poster
- Posts: 4
- Joined: Sun Sep 11, 2011 8:12 am
Re: 10370 - above average :
when we use long double .?can you help me.please
-
- New poster
- Posts: 1
- Joined: Wed Sep 14, 2011 5:03 pm
Re: 10370 - Above Average runtime error???
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;
}
#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;
}
-
- New poster
- Posts: 2
- Joined: Fri Feb 01, 2013 4:12 pm
Re: 10370 - Above Average
getting run time error....how...why
#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;
}

#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10370 - Above Average
Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!
Re: 10370 - Above Average
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!!!!
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!!!!

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10370 - Above Average
Change line 6 to:
int inp[1000];
int inp[1000];
Check input and AC output for thousands of problems on uDebug!
Re: 10370 - Above Average
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
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10370 - Above Average
Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
10370 - above average
Hello, everybody. I got WA for my code but I don't know why.
Please help me
thx~
Please help me

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;
}