c++ UVA 579 - ClockHands wrong answer -
i trying solve question system keep giving me "wrong answer". checked other people's solution , i'm sure algorithm correct. can me it? lot. question: uva 579 clockhands
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { int hour, minute; float hour_degree, minute_degree; float total; while(scanf("%d:%d",&hour, &minute) == 2) { if( hour == 0 && minute == 0) break; minute_degree = minute * 6; hour_degree = hour * 30 + float(minute / 2); total = fabs(hour_degree - minute_degree); if(total > 180) total = fabs(360 - total); printf("%.3f\n", total); } return 0; }
i spotted bug here
hour_degree = hour * 30 + float(minute / 2);
you doing integer division, , goes wrong if minute
odd number. should be
hour_degree = hour * 30 + float(minute / 2.0);
Comments
Post a Comment