Page 2 of 5

Posted: Wed Oct 08, 2003 3:21 pm
by Subeen
check ur output format. :o
ur format: %.3lf! (40.000!)
sample output format: %.3lf%% (40.000%)

Hey man thanx

Posted: Fri Oct 10, 2003 4:02 pm
by Riyad
Hey man so stupid of me . :oops:
i did a amazing job isnt it ??? :lol:
thanx any how :roll:
Bye
Riyad :wink:

10370 above average plz help me out

Posted: Sat Jul 10, 2004 12:27 pm
by majid
my code is running very acurate with the given input but when i tried to submit it it gives me wrong answer i m very much worried plzzzzz help me here is my code

Code: Select all

[cpp]
#include<iostream>
#include<iomanip>

using namespace std;
int tempor=0;
float *temp;
float *arr=NULL;
int size;
int s;
void average(float *array);
void print();
int main()
{
	cin>>s;
	arr=new float [s];
	temp=new float [s];
	for(int i=0;i<s;i++)
	{
		cin>>arr[i];
		size = arr[i];
		float *array=NULL;
		array=new float [size];
		for(int j=0;j<size;j++)
		{
			cin>>array[j];
		}
	
		average(array);
	}
	print();
	return 0;
}
void average(float *array)
{
	float count=0;
	float sum=0;
	float avg=0.00;
	for(int i=0;i<size;i++)
	{
		sum=sum+array[i];
	}
	avg=sum/size;
	for(int l=0;l<size;l++)
	{
		
		if(array[l]>avg)
			count++;
	}
	avg=(count*100)/size;
	temp[tempor++]=avg;
	
	
}
void print()
{
	
	for(int i=0;i<s;i++)
	{
		if(temp[i]==1)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==2)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==3)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==4)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==5)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==6)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==7)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==8)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==9)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==10)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==11)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==12)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==13)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==14)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==15)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==16)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==17)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==18)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==19)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==20)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==21)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==22)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==23)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==24)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==25)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==26)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==27)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==28)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==29)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==30)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==31)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==32)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==33)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==34)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==35)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==36)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==37)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==38)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==39)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==40)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==41)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==42)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==43)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==44)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==45)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==46)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==47)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==48)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==49)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==50)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==51)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==52)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==53)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==54)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==55)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==56)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==57)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==58)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==59)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==60)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==61)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==62)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==63)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==64)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==65)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==66)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==67)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==68)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==69)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==70)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==71)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==72)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==73)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==74)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==75)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==76)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==77)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==78)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==79)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==80)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==81)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==82)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==83)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==84)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==85)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==86)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==87)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==88)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==89)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==90)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==91)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==92)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==93)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==94)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==95)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==96)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==97)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==98)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==99)
			cout<<temp[i]<<".000%"<<endl;
		else if(temp[i]==100)
			cout<<temp[i]<<".000%"<<endl;
		else
			cout<<setprecision(5)<<temp[i]<<"%"<<endl;
			
	}
}
[/cpp]

10370 above average i m in great trouble plz help me

Posted: Sat Jul 10, 2004 3:30 pm
by majid
this code is giving wrong answer to me i dont know why plz tell me
here is my code


Code: Select all

[cpp]
#include<iostream>
#include<iomanip>

using namespace std;
int tempor=0;
float *temp;
float *arr=NULL;
int size;
int s;
void average(float *array);
void print();
int main()
{
	cin>>s;
	arr=new float [s];
	temp=new float [s];
	for(int i=0;i<s;i++)
	{
		cin>>arr[i];
		size = arr[i];
		float *array=NULL;
		array=new float [size];
		for(int j=0;j<size;j++)
		{
			cin>>array[j];
		}
	
		average(array);
	}
	print();
	return 0;
}
void average(float *array)
{
	float count=0;
	float sum=0;
	float avg=0.00;
	for(int i=0;i<size;i++)
	{
		sum=sum+array[i];
	}
	avg=sum/size;
	for(int l=0;l<size;l++)
	{
		
		if(array[l]>avg)
			count++;
	}
	avg=(count*100)/size;
	temp[tempor++]=avg;
	
	
}
void print()
{
	int check = 0;
	float res = -1.0;
	for(int i=0;i<s;i++)
	{
		check = temp[i];
		res = temp[i] - check;
		if(res > 0)
			cout<<setprecision(5)<<temp[i]<<"%"<<endl;
		else
			cout<<temp[i]<<".000%"<<endl;
	}
}



[/cpp]

Posted: Wed Nov 24, 2004 8:13 pm
by dip
Hi,
The main thing is about Precision Error. Though you get all the correct output but there is some input you get those error. Try to use double instead of float, its a good practice. And one thing is, dont use ".000%", it will come automatically and dont need to store average. Just print the output on the real time, somethink like that :-
"printf("%.3lf%%\n",(double)cnt/(double)tot*100);". Hope it will you help you. Keep posting. :D

10370 WA Why ???

Posted: Wed Dec 15, 2004 3:38 pm
by jhonny_yang
I got this wrong but i already seek it for month didnt found what is the bug :

[c]
#include <stdio.h>

int main()
{
long n,jlhMurid,i,jk,ehm[500],average,nilai;

scanf("%ld",&n);
for (i=0;i<n;i++){
scanf("%ld",&jlhMurid);
nilai=0;average=0;
for (jk=0;jk<jlhMurid;jk++){
scanf("%ld",&ehm[jk]);
average+=ehm[jk];
}
average=average/jlhMurid;
for (jk=0;jk<jlhMurid;jk++){
if (average<ehm[jk])
nilai++;
}
printf("%.3lf%%\n",(double)nilai/(double)jlhMurid*100.00);
}

return 0;
}
[/c][/c]

Posted: Wed Dec 15, 2004 3:51 pm
by little joey
There can be as many as 1000 students in a class, but you only reserve memory for 500.
Change it and you'll get AC.

Thx

Posted: Thu Dec 16, 2004 5:21 pm
by jhonny_yang
little joey wrote:There can be as many as 1000 students in a class, but you only reserve memory for 500.
Change it and you'll get AC.
hiks ... thx bro. It's experience ... find it about month

Posted: Sun May 08, 2005 4:34 am
by AdamP
I'm getting a compile error when I run my program... here's the error

In order to get the right precision of the output I am using the "fixed" function found in the iomanip.h library. However the OJ doesn't like it, so I get a compile error, here's my code that's giving me an error and the error message I get from OJ

cout << fixed << setprecision(3) << (100.0 * percentAbove) << "%" << endl;


Here are the compiler error messages:

03546402_24.c: In function `int main()':
03546402_24.c:42: `fixed' undeclared (first use this function)
03546402_24.c:42: (Each undeclared identifier is reported only once
03546402_24.c:42: for each function it appears in.)

--

I'm just posting for some help in formatting the output so it compiles correctly. The compiler at my school accepts it w/o a problem, not sure why OJ doesn't.

Thanks,
Adam P

Posted: Mon May 09, 2005 10:06 am
by CDiMa
AdamP wrote:I'm getting a compile error when I run my program... here's the error

[...]

I'm just posting for some help in formatting the output so it compiles correctly. The compiler at my school accepts it w/o a problem, not sure why OJ doesn't.
You should submit your code as C++. This should make it compile without problem

Ciao!!!

Claudio

Posted: Mon May 09, 2005 10:09 pm
by AdamP
CDiMa -

I tried to submit it again making sure I selected C++ as the type of code. I'm still getting the same compile error.

Is there another library I need to include?I'm only using

<iomanip.h>
<iostream.h>

Thanks

Posted: Tue May 10, 2005 12:47 pm
by CDiMa
AdamP wrote:I tried to submit it again making sure I selected C++ as the type of code. I'm still getting the same compile error.
I was induced to think that it was submitted as C code by the compiler messages:

Code: Select all

03546402_24.c: In function `int main()': 
As you can see the file extension is .c
Is the file extension of your new submission still .c ?

Ciao!!!

Claudio

Posted: Tue May 10, 2005 5:41 pm
by AdamP
Yeah, still saying .c

I triple checked everything and still am getting the error =( is there a way to format the output w/o using the fixed function?

Here are the compiler error messages:

03553475_24.c: In function `int main()':
03553475_24.c:42: `fixed' undeclared (first use this function)
03553475_24.c:42: (Each undeclared identifier is reported only once
03553475_24.c:42: for each function it appears in.)

Posted: Tue May 10, 2005 6:20 pm
by CDiMa
AdamP wrote:Yeah, still saying .c

I triple checked everything and still am getting the error =( is there a way to format the output w/o using the fixed function?

Here are the compiler error messages:

03553475_24.c: In function `int main()':
03553475_24.c:42: `fixed' undeclared (first use this function)
03553475_24.c:42: (Each undeclared identifier is reported only once
03553475_24.c:42: for each function it appears in.)
Well, try to drop the .h in your #includes like this:

Code: Select all

#include <iostream>
#include <iomanip>
using namespace std;
Ciao!!!

Claudio

Posted: Tue May 10, 2005 6:36 pm
by AdamP
I got OJ to accept my code, however I'm getting WA. My code checks out for all of the sample data, it even tests for a case when there are 0 students, outputting that 0.000% are above average. Are there any other strange cases that I need to account for?