Q579: ClockHands
//Q579 ClockHands
//Accepted 2008-04-14 15:09:19
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void)
{
while(1)
{
float hr = 0, min = 0, degree;
char time[10], hrn[3] = {'\0', '\0', '\0'};
cin >> time;
if (strcmp(time, "0:00") == 0)
break;
if (strlen(time) == 4)
{
strncpy(hrn, time, 1);
hr = atoi(hrn);
min = atoi(time + 2);
}
else
{
strncpy(hrn, time, 2);
hr = atoi(hrn);
min = atoi(time + 3);
}
degree = abs((hr + (min / 60))* 30 - min * 6);
if (degree > 180)
degree -= 360;
cout << setprecision(3) << fixed
<< abs(degree) << endl;
}
}
留言