Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Line Input #1, t If t = "0:00" Then Exit Do x = Val(Left(t, 2)) y = Val(Right(t, 2)) x = x * 30 + y * 0.5 y = y * 6 If x > y Then ans = x - y Else ans = y - x End If If ans > 180 Then ans = 360 - ans Print #2, Format(ans, "#0.##0") Loop Close #1 Close #2 End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Line Input #1, x If x = "0:00" Then Exit Sub l = Val(Left(x, 2)) r = Val(Right(x, 2)) ans = Abs(l * 30 - r * 6) + r * 0.5 If ans > 180 Then Print #2, 360 - ans; Else Print #2, ans; End If Print #2, ".000" Loop Close #1 Close #2 End Sub
Private Sub Form_Load() 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, x If x = "0:00" Then Exit Do H = Val(Left(x, 2)) M = Val(Right(x, 2)) j = M * 6 If H = 12 Then i = M / 2 Else i = H * 30 + M / 2 End If If j > i Then change i, j ans = i - j If 360 - ans < ans Then ans = 360 - ans Print #2, ans Loop Close #2 Close #1
Dim N As String Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, N If N = "0:00" Then Exit Do aa = Split(N, ":") a2 = Val(aa(1)) * 360 / 60 a1 = (Val(aa(0)) - Val(aa(1)) / 60) * 360 / 12 ans = a1 - a2 If ans > 180 Then ans = 360 - ans End If Print #2, Format(ans, "#0.##0") Loop Close #2 Close #1 End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Line Input #1, t
If t = "0:00" Then Exit Do
x = Val(Left(t, 2))
y = Val(Right(t, 2))
x = x * 30 + y * 0.5
y = y * 6
If x > y Then
ans = x - y
Else
ans = y - x
End If
If ans > 180 Then ans = 360 - ans
Print #2, Format(ans, "#0.##0")
Loop
Close #1
Close #2
End Sub
阿瑋好,
回覆刪除很好。
還用了format函數來輸出格式化結果,很好。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Line Input #1, x
If x = "0:00" Then Exit Sub
l = Val(Left(x, 2))
r = Val(Right(x, 2))
ans = Abs(l * 30 - r * 6) + r * 0.5
If ans > 180 Then
Print #2, 360 - ans;
Else
Print #2, ans;
End If
Print #2, ".000"
Loop
Close #1
Close #2
End Sub
Private Sub Form_Load()
回覆刪除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, x
If x = "0:00" Then Exit Do
H = Val(Left(x, 2))
M = Val(Right(x, 2))
j = M * 6
If H = 12 Then
i = M / 2
Else
i = H * 30 + M / 2
End If
If j > i Then change i, j
ans = i - j
If 360 - ans < ans Then ans = 360 - ans
Print #2, ans
Loop
Close #2
Close #1
End Sub
Public Sub change(a, b)
c = a
a = b
b = c
End Sub
Y揚好,
回覆刪除你的這題輸出,確定都是整數嗎?
於是你用了".000"的假格式化輸出?
應該會錯吧?
高仔好,
而你的程式是沒有「格式化」輸出吧?
而change i,j 這樣的「副程式」呼叫,似乎沒什麼必要性,
反而讓程式容易出錯。
因為在函數和副程式的呼叫中,很重要的一點是,你要知道參數是「傳值呼叫」還是「傳址呼叫」。
(書上是用這兩個相似的名詞啦,其實就是「以數值呼叫」還是「以變數去呼叫」)
(前者是「現金借給朋友」,後一個是「當保人」會有連帶結果的)
等社團課再說清楚吧。
Dim N As String
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, N
If N = "0:00" Then Exit Do
aa = Split(N, ":")
a2 = Val(aa(1)) * 360 / 60
a1 = (Val(aa(0)) - Val(aa(1)) / 60) * 360 / 12
ans = a1 - a2
If ans > 180 Then
ans = 360 - ans
End If
Print #2, Format(ans, "#0.##0")
Loop
Close #2
Close #1
End Sub
小白好,
回覆刪除加些油了哦,檢驗的時間快到了,重新得到的機會,請把握。
這題沒什麼問題。就是format這個函數要學到就是了。