2012年11月20日 星期二

時針和分針的夾角

在一般的時鐘上通常有兩根指針:時針、分針。請從"in.txt"讀取時間,回應此十分針和時針的夾角。(所有角度接取最小度數 Ex:9:00是90度,不是-90度也不是270度)
時間格式:   H:M
1 <=H<=12
00<=M<=59
0:00代表輸入結束
輸入範例:
12:00
9:00
8:10
0:00
輸出範例:
0.000
90.000
175.000

3 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do
    Line Input #1, temp
    strr = Split(temp, ":")
    If Val(strr(0)) = 0 And Val(strr(1)) = 0 Then Exit Do
    If Val(strr(0)) > 6 Then strr(0) = Abs(12 - Val(strr(0)))
    If Val(strr(1)) > 30 Then strr(1) = Abs(60 - Val(strr(1)))
    If Val(strr(0)) > 0 Then degree = (Int(Abs(Val(strr(0)) - Val(strr(1))) * 60 * 60 * 0.0083) + 1)
    If Val(strr(1)) > 0 Then subsub = (Int(Val(strr(1)) * 60 * 0.0083) + 1)
    tempp = degree - subsub
    Print #2, Format(tempp, "0.000")
    minutee = 0: hourr = 0
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do Until EOF(1)
    Line Input #1, x
    If x = "0:00" Then Exit Do
    a = Val(Left(x, 2))
    b = Val(Right(x, 2))
    t = (a * 30 + 6 * b / 12) - 6 * b
    z = 360 - t
    If t > z Then Print #2, Format(z, "0.000") Else Print #2, Format(t, "0.000")
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do While Not EOF(1)
    Line Input #1, a
    b = Split(a, ":")
    If b(0) = "0" And b(1) = "00" Then End
    c = Val(b(1)) * 6 / 12
    t = ((Val(b(0)) * 30 + c) - Val(b(1)) * 6)
    g = 360 - t
    If t <= g Then Print #2, Format(t, "0.000")
    If t > g Then Print #2, Format(g, "0.000")
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除