// 演算法：把時針、分針各自轉成「離 12 點的角度」，相減取絕對值。
// Algorithm: convert each hand to its angle from 12 o'clock, then take the
// absolute difference. The hour hand also drifts 0.5° for every minute.
// 最後若夾角大於 180，較小角是 360 減去它 / If the gap exceeds 180°, the
// smaller angle is 360 minus it. All O(1) arithmetic.

#include <math.h>   // 提供 fabs（浮點絕對值）/ provides fabs (float absolute value)

double angleClock(int hour, int minutes) {
    // 時針角度：hour%12 把 12 點當成 0；每小時 30 度；每分鐘額外 0.5 度
    // Hour-hand angle: hour%12 maps 12→0; 30° per hour; plus 0.5° per minute
    double hourAngle = (hour % 12) * 30.0 + minutes * 0.5;

    // 分針角度：每分鐘 6 度（360 度 ÷ 60 分）
    // Minute-hand angle: 6° per minute (360° ÷ 60 minutes)
    double minuteAngle = minutes * 6.0;

    // 兩角相差，取絕對值（fabs 去掉正負號）/ absolute difference of the two angles
    double diff = fabs(hourAngle - minuteAngle);

    // 夾角不能超過 180；若超過就走另一邊 360-diff，取較小者
    // The angle can't exceed 180°; if it does, the other side (360-diff) is smaller
    return diff < 360.0 - diff ? diff : 360.0 - diff;
}
