10370 - Above Average

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

Moderator: Board moderators

Postby Subeen » Wed Oct 08, 2003 3:21 pm

check ur output format. :o
ur format: %.3lf! (40.000!)
sample output format: %.3lf%% (40.000%)
Subeen
Experienced poster
 
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh

Hey man thanx

Postby Riyad » Fri Oct 10, 2003 4:02 pm

Hey man so stupid of me . :oops:
i did a amazing job isnt it ??? :lol:
thanx any how :roll:
Bye
Riyad :wink:
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
User avatar
Riyad
Experienced poster
 
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET

10370 above average plz help me out

Postby majid » Sat Jul 10, 2004 12:27 pm

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]
majid
New poster
 
Posts: 3
Joined: Sat Jul 10, 2004 12:17 pm

10370 above average i m in great trouble plz help me

Postby majid » Sat Jul 10, 2004 3:30 pm

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]
majid
New poster
 
Posts: 3
Joined: Sat Jul 10, 2004 12:17 pm

Postby dip » Wed Nov 24, 2004 8:13 pm

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
something .....
dip
New poster
 
Posts: 7
Joined: Sat Nov 20, 2004 10:20 am
Location: Dhaka

10370 WA Why ???

Postby jhonny_yang » Wed Dec 15, 2004 3:38 pm

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]
jhonny_yang
New poster
 
Posts: 22
Joined: Fri Jan 17, 2003 8:24 am

Postby little joey » Wed Dec 15, 2004 3:51 pm

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.
User avatar
little joey
Guru
 
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Thx

Postby jhonny_yang » Thu Dec 16, 2004 5:21 pm

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
jhonny_yang
New poster
 
Posts: 22
Joined: Fri Jan 17, 2003 8:24 am

Postby AdamP » Sun May 08, 2005 4:34 am

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[i]) << "%" << 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
AdamP
New poster
 
Posts: 7
Joined: Sat May 07, 2005 5:20 am

Postby CDiMa » Mon May 09, 2005 10:06 am

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
CDiMa
Experienced poster
 
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Postby AdamP » Mon May 09, 2005 10:09 pm

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
AdamP
New poster
 
Posts: 7
Joined: Sat May 07, 2005 5:20 am

Postby CDiMa » Tue May 10, 2005 12:47 pm

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
CDiMa
Experienced poster
 
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Postby AdamP » Tue May 10, 2005 5:41 pm

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.)
AdamP
New poster
 
Posts: 7
Joined: Sat May 07, 2005 5:20 am

Postby CDiMa » Tue May 10, 2005 6:20 pm

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
CDiMa
Experienced poster
 
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Postby AdamP » Tue May 10, 2005 6:36 pm

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?
AdamP
New poster
 
Posts: 7
Joined: Sat May 07, 2005 5:20 am

PreviousNext

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 2 guests

cron