Page 1 of 3
579 - Clock Hands
Posted: Wed Jul 24, 2002 6:30 am
by mystical_liu
this is my code !!!
is there anybody can tell me where am i wrong!!!
[cpp]#include<stdio.h>
main()
{
int h,m,hn,mn;
float ans;
while(scanf(" %d:%d",&h,&m)==2)
{
if(!h&&!m)break;
ans=((h*60)*0.5)+(m*0.5)-(m*6);
if(ans>180)ans=360.000-ans;
else if(ans<0)ans*=-1;
printf("%.3f\n",ans);
}
}[/cpp]
Posted: Wed Jul 24, 2002 7:43 am
by Revenger
For example, on the test
the corect output is
Change your code is so way:
[cpp]if(ans<0)ans*=-1;
if(ans>180)ans=360.000-ans;[/cpp]
[/code]
OH!!!I GOt IT!!
Posted: Wed Jul 24, 2002 2:38 pm
by mystical_liu
OH!!!
I got it !!!!!
thinks a lot!!~!~
I know where am I wrong!!
thinks your remide!!!
579Why TL?!!
Posted: Thu Oct 16, 2003 5:24 pm
by Morning
[cpp]
#include<stdio.h>
void main()
{
float clock,minute;
float degree;
while(scanf("%f:%f",&clock,&minute)==2)
{
if(!clock&&!minute) break;
degree=(clock*30+minute/2)-minute*6;
while(degree<0)
{
degree+=180;
}
while(degree>=180)
{
degree=360-degree;
}
printf("%.3f\n",degree);
}
}
[/cpp]
Posted: Sun Oct 26, 2003 10:25 pm
by Tanzim-Saqib
I don't understand why these while loops (except for taking inputs) are necessary. Morning, just derive an equation where there will only be minutes and hour and nothing else, no more loops. Hope it helps.
Posted: Tue Oct 28, 2003 6:20 am
by Morning
thanx,i've gotten it:)
579 WA ><
Posted: Wed May 26, 2004 1:36 pm
by cytmike
[cpp]#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int p,h;
char y;
cin>>p>>y>>h;
while ((p!=0)&&(y!=0))
{
long double l=abs(p*30-h*5.5);
if (l>180)
l=360-l;
cout<<setiosflags(ios::showpoint|ios::fixed)<<setprecision(3)<<l<<endl;
cin>>p>>y>>h;
}
return 0;
}
[/cpp]
What happened!!??
Posted: Wed May 26, 2004 11:23 pm
by UFP2161
[c]1:01[/c]
should output
[c]24.500[/c]
Posted: Thu May 27, 2004 2:56 pm
by cytmike
my program outputs 24.500 too...

Posted: Thu May 27, 2004 5:09 pm
by UFP2161
Ah, I think I see the problem.
When I originally compiled your program I got the following warning:
g++ test.cpp
test.cpp: In function `int main()':
test.cpp:13: warning: `double' used for argument 1 of `abs(int)'
However, when I #include <cmath>, it works as expected.
The judge is probably doing the same thing. There are overloaded abs() operators in the <cmath> header file, but the default std::abs only takes and returns an int, which is probably causing your WA.
Posted: Fri May 28, 2004 12:59 am
by cytmike
but why i can compile it correctly, but the judge cannot???

Posted: Fri May 28, 2004 1:18 am
by UFP2161
In your environment, your compiler might auto-include <cmath> which has the overloaded operators, but the judge's system, as well as most standard UNIX systems, will not.
Posted: Fri May 28, 2004 6:01 pm
by cytmike
ic
thank you very much
579
Posted: Sat Sep 25, 2004 10:36 am
by efr_shovo
/* Why 579 Gives Wrong Ans Please Help*/
#include<stdio.h>
#include<ctype.h>
char time1[4];
int hour,minute,mutex,ex;
float deg;
int Digit(int *d)
{
int digit;
int g=*d;
int b10=0;
while(isdigit(time1[g]))
{
b10*=10;
digit=(int(time1[*d])-48)+b10;
b10=digit;
g++;
*d=g;
}
return digit;
}
void main()
{
while(1)
{ int i=0;
scanf("%s",time1);
for(i=0;i<4;i++)
{
if(!mutex)
{
if(isdigit(time1))
{
hour=Digit(&i);
mutex=1;
}
}
else
{
minute=Digit(&i);
mutex=0;
}
}
if(!hour && !minute)
break;
if(hour>12)
hour=0;
else
hour=12-hour;
deg=float((hour*30)+(minute*6+minute/60)-(.5*float(minute)));
if(deg<0)
deg*=-1;
if(deg>180.0)
{
deg=float(360)-deg;
deg*=-1;
}
printf("%.3f\n",deg);
}
}
Posted: Sun Sep 26, 2004 6:23 am
by Ghust_omega
Hi!! efr_shovo try with this I/O
Input:
Code: Select all
0:46
11:55
1:55
12:12
1:00
2:00
0:19
12:46
9:00
10:16
7:00
3:00
3:50
2:43
10:55
9:42
1:18
5:27
10:16
9:22
1:33
3:59
4:37
5:44
4:30
1:46
0:20
2:33
11:50
6:00
10:45
10:27
1:00
4:00
11:17
12:15
0:45
3:27
9:44
7:50
00:00
ouput:
Code: Select all
107.000
27.500
87.500
66.000
30.000
60.000
104.500
107.000
90.000
148.000
150.000
90.000
175.000
176.500
2.500
39.000
69.000
1.500
148.000
149.000
151.500
125.500
83.500
92.000
45.000
137.000
110.000
121.500
55.000
180.000
52.500
151.500
30.000
120.000
123.500
82.500
112.500
58.500
28.000
65.000
Hope its helps
Keep posting!!
