Ref: UVa Online Judge - UVa 579 Clock Hands
/*******************************************************/
/* UVa 579 - Clock Hands */
/* Author: awei0905 [at] awei0905.blogspot.tw */
/* Version: 2017/04/07 */
/*******************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main() {
float H, M, ans;
char input[6], *token;
while (scanf("%s", input) != EOF) {
token = strtok(input, ":");
H = atof(token);
token = strtok(0, ":");
M = atof(token);
if (H == 0.0 && M == 0.0)
break;
H = H * 30 + 0.5 * M;
M = 6 * M;
ans = abs(H - M);
if (ans > 180)
H = 360 - ans;
else
H = ans;
printf("%.3f\n", H);
}
}
Debug: I/O, uDebug1:59
1:01
0:00
65.500
24.500
沒有留言:
張貼留言