https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=520 困難度 ★ 這提示輸入時針和分針顯示出在時鐘上最小的角度 首先先計算時針角度h_hand=h(360/12)+(m/60)(360/12) //一圈360度除以12代表每個小時幾度還要再加分針影響時針的角度 再來計算分針的角度m_hand=m*(360/60)//一圈360度除以60代表每一分走幾度 然後再取時針減分針角度的絕對值,最後還沒完成哦!還要判斷假如最後出來的絕對值小於180要再用360減去才是最小角
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
String str = scn.next(), arr[] = str.split(":");
if (str.equals("0:00"))
break;
double h = Double.parseDouble(arr[0]), m = Double.parseDouble(arr[1]), h_hand, m_hand, tot = 0.0;
h_hand = h * (360 / 12) + m / 60 * (360 / 12);
m_hand = m * (360 / 60);
tot = Math.abs(h_hand - m_hand);
System.out.printf("%.3f\n", tot < 180 ? 360 - tot : tot);
}
}
/*
題目:Q579 : Clock Hands
作者:1010
時間:西元 2016 年 7 月 */
}