|
|
back to boardWA3 Posted by rohit 16 May 2008 02:31 This is my code. #include<stdio.h> #include<math.h> double min(int t,int s) { switch (t) { case 1: return 2*s; case 2: return (double)s; default: return ((s/2)*sqrt(3.0)); } } double max(int t,int s) { switch (t) { case 1: return 2*s; case 2: return (s*sqrt(2.0)); default: return (double)s; } } void main() { int htype,hsize; int type,size; double max_len,min_len; int n,c=0; int i; scanf("%d %d",&htype,&hsize); max_len=max(htype,hsize); scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d %d",&type,&size); min_len=min(type,size); if (min_len<=max_len) c++; } printf("%d",c); } Please tell me whats wrong.. Re: WA3 Perhaps, the error is in the function "min". In case of triangle you return ((s/2)*sqrt(3.0)); But in C++ when "s" is "int" and "2" is "int", you will get not float division but only integer division. So when s==3, for example, ((s/2)*sqrt(3.0))==1*sqrt(3.0) You may write "s/2.0". Re: WA3 Posted by rohit 27 Jul 2010 23:02 Thanks..AC now. Such a silly mistake. |
|
|