Why TL?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Why TL?

Post by Morning »

when i solve problems,i always got TL.My code is below:
[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]
and there's someone who can get AC
[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]
p.s :the problem is No.579
who can tell me why?
"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
Viktoras Jucikas
New poster
Posts: 22
Joined: Sun Oct 20, 2002 6:41 pm
Location: Lithuania
Contact:

Post by Viktoras Jucikas »

Doing ! for floats is not a good idea... (afaik you cannot represent 0.0 using ieee floats, it's always either greater or smaller than 0.0 for some epsilon)
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Post by Morning »

I know what's the problem.I shoudn't use while().
Nevertheless,thanks for your useful suggestion:)
"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
Post Reply

Return to “C++”