Page 3 of 5

10370 I don't know why i got WA please help me

Posted: Thu Feb 02, 2006 8:12 pm
by sv90
HERE IS MY CODE I GOT WA WHY
i remove my code

Posted: Sun Feb 05, 2006 9:00 am
by Wei-Ming Chen
for(k=0;k<=n;k++)
{
if(a[k]>av)
{
count++;
}
}


k<=n??
I thought is k<n

Re: 10370 I don't know why i got WA please help me

Posted: Sun Feb 05, 2006 10:45 am
by sv90
sv90 wrote:HERE IS MY CODE I GOT WA WHY
thanks

10370 WA?! why?

Posted: Sat Feb 11, 2006 4:13 pm
by mek027
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;
}

Posted: Sun Feb 12, 2006 4:59 am
by wook
i think there was a precision error....

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++; 
} 
is proabably making a trivial error!

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.

Posted: Mon Feb 13, 2006 4:13 pm
by mek027
hello
tanX for your help
i do your offers but still give WA

10370

Posted: Sat Mar 11, 2006 8:28 am
by mek027
plz give me some I/O for 10370(above average)
Tx alot

10370 Compile Error :-(

Posted: Thu Jul 27, 2006 6:24 am
by goodluck
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;
}

Posted: Thu Jul 27, 2006 6:34 pm
by jan_holmes
I think it is because you defined variable k inside k... I changed your code a bit

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

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... :wink:

10370(restircted function error)

Posted: Mon Aug 21, 2006 3:38 pm
by sobuz
#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;
}

Posted: Wed Aug 23, 2006 2:22 pm
by kolpobilashi
since your return type in main() function is int so you need to return a value.so change your code to:

Code: Select all

return 0;
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

Code: Select all

printf("%.3f%\n",percent); 
to:

Code: Select all

printf("%.3f%c\n",percent,'%');
hope u'll get AC :)

Posted: Fri Apr 06, 2007 12:43 pm
by ranacse05
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;
}

10370-WA,please help

Posted: Tue Jan 08, 2008 3:22 pm
by jesun
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:

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

Posted: Wed Jan 30, 2008 9:02 am
by Obaida
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;
}

Posted: Wed Jan 30, 2008 6:26 pm
by DanielMarques
No need for the while loop:

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++)
{
...
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.