10370 - Above Average
Moderator: Board moderators
10370 I don't know why i got WA please help me
HERE IS MY CODE I GOT WA WHY
i remove my code
i remove my code
Last edited by sv90 on Sun Feb 05, 2006 10:48 am, edited 1 time in total.
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
Re: 10370 I don't know why i got WA please help me
sv90 wrote:HERE IS MY CODE I GOT WA WHY
thanks
10370 WA?! why?
i got WA plz help me
this is my code :
#include<stdio.h>
int main()
{
int tc,n,grade[100],i,c=0;
double ave,p,sum=0;
scanf("%d",&tc);
while(tc)
{
p=0.000;sum=0.000;c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&grade);
sum+=grade;
}
ave=((double)sum/(double)n);
for(i=0;i<n;i++)
{
if(grade>ave)
c++;
}
p=(((double)c*(double)100)/(double)n);
printf("%.3lf%%\n",p);
tc--;
}
return 0;
}
this is my code :
#include<stdio.h>
int main()
{
int tc,n,grade[100],i,c=0;
double ave,p,sum=0;
scanf("%d",&tc);
while(tc)
{
p=0.000;sum=0.000;c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&grade);
sum+=grade;
}
ave=((double)sum/(double)n);
for(i=0;i<n;i++)
{
if(grade>ave)
c++;
}
p=(((double)c*(double)100)/(double)n);
printf("%.3lf%%\n",p);
tc--;
}
return 0;
}
i think there was a precision error....
since a is integer, sum is integer, too.
the code
is proabably making a trivial error!
the inequation
is equal to
for n is positive.
In this way, you use no real-valued variant,
i.e. using ONLY INTEGER VARIANTS -- without precision errors,
you can get a correct answer, I tink.
since a is integer, sum is integer, too.
the code
Code: Select all
ave=((double)sum/(double)n);
for(i=0;i<n;i++)
{
if(grade[i]>ave)
c++;
}
the inequation
grade > (sum/n)
is equal to
grade * n > sum
for n is positive.
In this way, you use no real-valued variant,
i.e. using ONLY INTEGER VARIANTS -- without precision errors,
you can get a correct answer, I tink.
Sorry For My Poor English.. 

10370 Compile Error :-(
i think it's very easy,but...
this is my code,can anybody tell me why?
#include<stdio.h>
int main()
{
int sum=0;
int a[100];
int i,j,k,c;
scanf("%d",&i);
for(k=0;k<i;k++)
{
scanf("%d",&j);
for(k=0;k<j;k++)
{
scanf("%d",&a[k]);
sum+=a[k];
}
c=0;
for(k=0;k<j;k++)
{
if(a[k]>float(sum/j)) c++;
}
printf("%.3f%%\n",(float)c/j*100);
}
return 0;
}
this is my code,can anybody tell me why?
#include<stdio.h>
int main()
{
int sum=0;
int a[100];
int i,j,k,c;
scanf("%d",&i);
for(k=0;k<i;k++)
{
scanf("%d",&j);
for(k=0;k<j;k++)
{
scanf("%d",&a[k]);
sum+=a[k];
}
c=0;
for(k=0;k<j;k++)
{
if(a[k]>float(sum/j)) c++;
}
printf("%.3f%%\n",(float)c/j*100);
}
return 0;
}
-
- Experienced poster
- Posts: 136
- Joined: Fri Apr 15, 2005 3:47 pm
- Location: Singapore
- Contact:
I think it is because you defined variable k inside k... I changed your code a bit
but I think this will give you runtime error because you defined size of array a only 100... you should add the size of array a also...
Hope it helps...
Code: Select all
#include<stdio.h>
int main()
{
int sum=0;
int a[100];
int i,j,k,c,z;
scanf("%d",&i);
for(k=0;k<i;k++)
{
scanf("%d",&j);
for(z=0;z<j;z++)
{
scanf("%d",&a[z]);
sum+=a[z];
}
c=0;
for(z=0;z<j;z++)
{
if(a[z]>float(sum/j)) c++;
}
printf("%.3f%%\n",(float)c/j*100);
}
return 0;
}
Hope it helps...

10370(restircted function error)
#include<stdio.h>
int main()
{
unsigned long p,q,n,count=0,grade[10000],sum=0,index,ca;
float avg,percent,t;
scanf("%lu\n",&ca);
for(index=1;index<=ca;index++)
{
scanf("%lu\t",&n);
if(n<=1000)
{
for(p=1;p<=n;p++)
{
scanf("%lu",&grade[p]);
sum+=grade[p];
avg=sum/n;
}
for(p=1;p<=n;p++)
{
if(avg<grade[p])
count++;
}
t=(float)count/n;
percent=t*100;
printf("%.3f%\n",percent);
count=0;
sum=0;
percent=0;
}
}
return;
}
int main()
{
unsigned long p,q,n,count=0,grade[10000],sum=0,index,ca;
float avg,percent,t;
scanf("%lu\n",&ca);
for(index=1;index<=ca;index++)
{
scanf("%lu\t",&n);
if(n<=1000)
{
for(p=1;p<=n;p++)
{
scanf("%lu",&grade[p]);
sum+=grade[p];
avg=sum/n;
}
for(p=1;p<=n;p++)
{
if(avg<grade[p])
count++;
}
t=(float)count/n;
percent=t*100;
printf("%.3f%\n",percent);
count=0;
sum=0;
percent=0;
}
}
return;
}
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
since your return type in main() function is int so you need to return a value.so change your code to:
and you should print a % after each output according to the problem's output format, but your code fails to print this.chage your code
to:
hope u'll get AC 
Code: Select all
return 0;
Code: Select all
printf("%.3f%\n",percent);
Code: Select all
printf("%.3f%c\n",percent,'%');

Sanjana
Will any one rell me where is the problem??
Here is my code:#include<stdio.h>
int main()
{
int a,num,i,j,k,az,stu[110];
double sh,ave,kl,al;
while(scanf("%d",&num)==1)
{
for(i=0;i<num;i++)
{
scanf("%d",&a);
ave=0;az=0;kl=0;al=0;
for(j=0;j<a;j++)
{
scanf("%d",&stu[j]);
ave+=stu[j];
}
ave/=a;
k=0;az=0;
az=(int)ave;
for(j=0;j<a;j++)
{
if(stu[j]>az)
k++;
}
kl=(float)k;
al=(float)a;
sh=(kl/al);
printf("%.3lf%\n",sh*100);
}
}
return 0;
}
Here is my code:#include<stdio.h>
int main()
{
int a,num,i,j,k,az,stu[110];
double sh,ave,kl,al;
while(scanf("%d",&num)==1)
{
for(i=0;i<num;i++)
{
scanf("%d",&a);
ave=0;az=0;kl=0;al=0;
for(j=0;j<a;j++)
{
scanf("%d",&stu[j]);
ave+=stu[j];
}
ave/=a;
k=0;az=0;
az=(int)ave;
for(j=0;j<a;j++)
{
if(stu[j]>az)
k++;
}
kl=(float)k;
al=(float)a;
sh=(kl/al);
printf("%.3lf%\n",sh*100);
}
}
return 0;
}
10370-WA,please help
I can't figure out the bug in my solution to problem no 10370?Could anyone help me? And sorry for opening a new thread although there is one because I didn't know about that rule/request.i hope I shall not do this in coming future.
here is my code:
here is my code:
Code: Select all
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
#include <stdio.h>
//#include <conio.h>
int main()
{
int m,n,i,j;
float result=0.000;
cin>>n;
while(n)
{
cin>>m;
if(m==0)
{
printf("0.000");
cout<<"%"<<endl;
n--;
continue;
}
vector<int> record(m);
j=0;
for(i=0;i<m;i++)
{
cin>>record[i];
}
if(m==1)
{
printf("0.000");
cout<<"%"<<endl;
n--;
continue;
}
for(i=0;i<m;i++)
{
result+=record[i];
}
result=result/m;
for(i=0;i<m;i++)
{
if(record[i]>result)
{
j++;
}
}
result=(float)j/(float)m;
printf("%.3f",result*100.000);
cout<<"%"<<endl;
n--;
}
//getch();
return 0;
}
10370
Some one plezzzzzz help me this program is calculating for the first input but not working for the next inputs.....
Code: Select all
#include<stdio.h>
int main()
{
long int n,x[1000],i,m;
long double sum,ave,ans,count;
while(scanf("%ld",&m)==1)
{
for(i=1;i<=m;i++)
{
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
scanf("%ld",&x[i]);
}
sum=0;
for(i=1;i<=n;i++)
{
sum=sum+x[i];
}
ave=0;
ave=sum/n;
count=0;
ans=0;
for(i=1;i<=n;i++)
{
if(x[i]>ave)
count++;
}
ans=(count/n)*100;
printf("%.3Lf%%\n",ans);
}
}
return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- New poster
- Posts: 5
- Joined: Thu Jan 24, 2008 7:13 pm
- Location: Rio de Janeiro
No need for the while loop:
One more thing, you're already using 'i' as the count in the first for loop, so you must choose a different variable in the other for's.
Code: Select all
long int n,x[1000],i,m;
long double sum,ave,ans,count;
scanf("%ld",&m);
for(i=1;i<=m;i++)
{
...