579 - Clock Hands
Moderator: Board moderators
-
- New poster
- Posts: 9
- Joined: Sun Jul 21, 2002 1:18 pm
579 - Clock Hands
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]
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]
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]
Code: Select all
1:59
Code: Select all
65.500
[cpp]if(ans<0)ans*=-1;
if(ans>180)ans=360.000-ans;[/cpp]
[/code]
-
- New poster
- Posts: 9
- Joined: Sun Jul 21, 2002 1:18 pm
OH!!!I GOt IT!!
OH!!!
I got it !!!!!
thinks a lot!!~!~
I know where am I wrong!!
thinks your remide!!!
I got it !!!!!
thinks a lot!!~!~
I know where am I wrong!!
thinks your remide!!!
579Why TL?!!
[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]
#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]
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
-
- New poster
- Posts: 10
- Joined: Thu Jun 05, 2003 5:23 pm
- Location: CS, AIUB, Dhaka, Bangladesh
- Contact:
-
- Learning poster
- Posts: 95
- Joined: Mon Apr 26, 2004 1:23 pm
- Location: Hong Kong and United States
- Contact:
579 WA ><
[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!!??
#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!!??
Ah, I think I see the problem.
When I originally compiled your program I got the following warning:
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.
When I originally compiled your program I got the following warning:
However, when I #include <cmath>, it works as expected.g++ test.cpp
test.cpp: In function `int main()':
test.cpp:13: warning: `double' used for argument 1 of `abs(int)'
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.
579
/* 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);
}
}
#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);
}
}
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
Hi!! efr_shovo try with this I/O
Input:
ouput:
Hope its helps
Keep posting!!
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
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
Keep posting!!